Hey guys, I got a doc type called Distributor with a property of email on it. All I want to do is redirect a user to that node when they log in. But how do I get the node knowing the emal address? This is what I have so far and it's not working.
var memberNode = @Model.Distributor.email(currentUser.UserName);
The currentUser.UserName is the email address, all users on this site will use their email address as their login.
This razor stuff is really new to me. Sorry if this is really simple.
I have a node called CompanyDistributors with an id of 9864. Below that are distributors, nodes with the docType Distributor On the distributor document is a property called email.
All I need to do is find the node with the email that matches the current members login... so this is what I have.
this gets the current user var currentUser = Membership.GetUser();
this is my latest attempt to get the distributor node. This is throwing an error though. . var distNode = @Model.NodeById(9864).Descendants("Distributors").Where("email=" + currentUser.UserName);
No that gives me a wierd error Error loading Razor Script memberRedirect.cshtml 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'DescendantsOrSelf'
Ok, that does make a change, I now get a syntax error.
this gets no error but returns a umbraco.MacroEngines.DynamicNodeList var distNode = @Model.AncestorOrSelf().DescendantsOrSelf("Distributor")
this gives me a syntax error, so something is wrong in the Where clause. var distNode = @Model.AncestorOrSelf().DescendantsOrSelf("Distributor").Where("email == " + currentUser.UserName).FirstOrDefault();;
Newbie Get a specific node quesiton
Hey guys, I got a doc type called Distributor with a property of email on it. All I want to do is redirect a user to that node when they log in. But how do I get the node knowing the emal address? This is what I have so far and it's not working.
var memberNode = @Model.Distributor.email(currentUser.UserName);
The currentUser.UserName is the email address, all users on this site will use their email address as their login.
This razor stuff is really new to me. Sorry if this is really simple.
Can you clarify: You basically want to find a node of a given DocType by the value of it's property, starting from anywhere in your site?
Yes, that is what I want to do.
I have a node called CompanyDistributors with an id of 9864.
Below that are distributors, nodes with the docType Distributor
On the distributor document is a property called email.
All I need to do is find the node with the email that matches the current members login... so this is what I have.
this gets the current user
var currentUser = Membership.GetUser();
this is my latest attempt to get the distributor node. This is throwing an error though. .
var distNode = @Model.NodeById(9864).Descendants("Distributors").Where("email=" + currentUser.UserName);
OK, off the top of my head you should be able to do something like this:
No that gives me a wierd error
Error loading Razor Script memberRedirect.cshtml
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'DescendantsOrSelf'
In the code snippet change AncestorsOrSelf() to AncestorOrSelf() (no "s" on Ancestor)
Ok, that does make a change, I now get a syntax error.
this gets no error but returns a umbraco.MacroEngines.DynamicNodeList
var distNode = @Model.AncestorOrSelf().DescendantsOrSelf("Distributor")
this gives me a syntax error, so something is wrong in the Where clause.
var distNode = @Model.AncestorOrSelf().DescendantsOrSelf("Distributor").Where("email == " + currentUser.UserName).FirstOrDefault();;
ignore the double ; at the end of that line... That was a mistake with the copy and paste
I forgot the First() bit so try:
This is how I finally got it to work. For whatever reason it really didn't like the syntax for
Where("email == "+ currentUser.UserName)
No matter what I tried, it would always give me a syntax error for that, even though it looks right to me.
But here is the working code, let me know what you think.
@{
var currentUser = Membership.GetUser();
}
@foreach(var page in Model.NodeById(9864).Children){
if(@page.email == currentUser.UserName)
{
Response.Redirect(@page.Url);
}
}
Realised the problem with the Where clause - you need to resolve it before passing it. So you could do
and then you should be able to do
Thanks Dan, that worked! Very awesome!
is working on a reply...