Question

I have a partial view/user control called LogOnUserControl which I display in a side bar on my site (defined in Site.Master). I also have a separate LogOn view, which also renders the LogOnUserControl.

I don't want two instances of the LogOnUserControl in the LogOn view, because it's just plain confusing, so my current thinking is to include a condition such as

// Semi-pseudocode
if (!Request.IsAuthenticated) && View.Name != "LogOn")

in the LogOnUserControl.

This feels wrong, as the partial view now knows about the LogOn view. Also, I can't find out how to get the View's name, which reinforces the feeling that I'm doing something wrong! :-)

Edit: There is the further complication that the same partial view is used for both the LogOn view and the sidebar in Site.Master.

Was it helpful?

Solution

On the master page wrap the content of the sidebar area with content area tags and give it an id like SideBarContentArea or something. What this does is create a new content area that you can choose to override on pages based of the master and specifies default content that will show up when you do not implement in on the child pages. Now on the login page all you have to do is override the SideBarContentArea and not include the login control this time.

Bada Bing!

OTHER TIPS

Have you considered using a different master page for your login View without the login partial in the sidebar? If you are concerned about duplication of html markup you could use nested master pages to avoid that issue.

You could store a flag in ViewData to indicate this. Whether you want to strong-type it or just access it directly is up to you. So on your master page you could have this:

<% if (ViewData["HideLogOnUserControl"] == "Y") { %>
    Insert HTML here
<% } else { %>
    Insert HTML here
<% } %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top