开发者

display users full name instead of user name

I am using MVC3. I need to display the user's full name in the master page after the successful login i.e. welcome Jack. The full name is in another table called 'UserProfile'. In the traditional asp.net web forms, I could do that easily. But I have no clue how to do that in MVC..!! I have a partial view name 'LogOnUserControl.ascx'开发者_如何学JAVA. In this partial view I have the following code that shows the login user name.

Welcome <strong><%: Page.User.Identity.Name %></strong>!

If the right click on this and click on 'go to controller', it does not go anywhere. Can anyone please guide me about how to get the users original name??


For this case you can use a child action. Assuming that you already have set up your authentication you can in your child action lookup into the UserProfile table and render a partial view with a view model representing the user data.

So in your Master Page you will have:

<%= Html.RenderAction("UserLogonInfo", "Account")%>

Then you can have an account controller with a child action which will get user data and render it:

    [ChildActionOnly]
    public PartialViewResult UserLogonInfo()
    {
        IPrincipal principal = HttpContext.User;
        LogonInfoViewModel model = UserDataRepository.GetUserLogonInfo(principal);
        return PartialView(model);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜