Asp.Net Mvc – How to have a “controller” in shared view

In your contoller action you could specify the name of the view:

public class MenuController : Controller
{
    [ChildActionOnly]
    public ActionResult Header()
    {
        var model = ... // go to the database and fetch a model
        return View("~/Views/Shared/_Header.cshtml", model);
    }
}

Now in your _Layout.cshtml instead of @Html.Partial("_Header") do this:

@Html.Action("Header", "Menu")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)