开发者

ASP.NET MVC: How to implement a Login type partial view that changes depending if logged in or not?

I would like to know if what the best method is for creating a login type control i.e. When not logged in, offers links to login etc and when logged in offers the users name and setting etc.

I was thinking that the proper way to go about this is a partial view?

But does mean i need to insert IFs in the partial view to render depending if logged in or not?

I don't know if开发者_如何学JAVA this is the best way? Maybe its a bit messy?

I would really love some feedback or any ideas.

I am using MVC 3


If you open up Visual Studio 2010 and create a new ASP.NET MVC Website (not the empty one), they have an example of how you could do this.

It is pretty much how you described it. It would be something similar to the following

@if(Request.IsAuthenticated) {
    Hello @Page.User.Identity.Name
} else {
    @Html.ActionLink("Sign In", "SignIn", "Account")
}

Given how short and simple this is, I don't think it would be considered messy.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜