Reputation: 9752
I am trying to insert a custom header (held in a database) on my master page. The custom header changes on a user by user basis.
I'm slightly confused on how to attach a controller to a partial (if I even can do this). What I'm hoping to accomplish is to render a block of code from a specific controller called with some events.
public ActionResult GetHeader(Guid clientID)
{
string szHeader = GetTheme(ThemeType.Portal, JoloTheme.ThemeArea.Header, clientID);
return Content(szHeader, "text/html");
}
Is the controller I have created, but I'm not sure how to get this onto a subsection of a page I am currently writing (not in the same Controller).
Apologies if this is completely nonsense here, still learning MVC I'm afraid.
Upvotes: 1
Views: 232
Reputation: 38478
You should use Html.Action() helper in your _Layout.cshtml. I think you should use a Nullable Guid as a parameter because you won't be able to provide a valid clientID always.
public ActionResult GetHeader(Guid? clientID)
{
string szHeader = GetTheme(ThemeType.Portal, JoloTheme.ThemeArea.Header, clientID);
return Content(szHeader, "text/html");
}
Here's how you should call Html.Action helper in your _Layout.cshtml
@Html.Action("GetHeader",
"SomeController",
new { clientID = IsLoggedIn ? ClientID : (Guid?)null } )
Upvotes: 2