Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @{Html.RenderAction("UserInfo", "Account");}
- public class UserInfo()
- {
- public bool IsAuthenticated {get;set;}
- public string ForeName {get;set;}
- }
- public PartialViewResult UserInfo()
- {
- var model = new UserInfo();
- model.IsAutenticated = httpContext.User.Identity.IsAuthenticated;
- if(model.IsAuthenticated)
- {
- // Hit the database and retrieve the Forename
- model.ForeName = Database.Users.Single(u => u.UserName == httpContext.User.Identity.UserName).ForeName;
- //Return populated ViewModel
- return this.PartialView(model);
- }
- //return the model with IsAuthenticated only
- return this.ParitalView(model);
- }
- @model UserInfo
- @if(Model.IsAuthenticated)
- {
- <text>Hello, <strong>@Model.ForeName</strong>!
- [ @Html.ActionLink("Log Off", "LogOff", "Account") ]
- </text>
- }
- else
- {
- @:[ @Html.ActionLink("Log On", "LogOn", "Account") ]
- }
Add Comment
Please, Sign In to add comment