I have a simple PartialView setup in my MVC3 Project using the Razor View Engine.
The Partial will render but if I set a breakpoint in the controller on the Action for the Partial, it never gets hit. If I change the URL to go directly to the PartialView, i.e. http://localhost:13965/Home/GridControl, then the breakpoint is hit. What am I missing?
My view:
@model MyModel
@Html.Partial("GridControl", Model)
My Controller:
public ActionResult GridControl()
{
return PartialView();
}
Html.Partialdoesn’t call a controller action. It is a simple include of a partial view at the place you called it.If you want to call the controller action you need to use the Html.Action or Html.RenderAction helper like this:
or:
And obviously in this case you are not passing any model as your controller action doesn’t expect any model as argument and it is its responsibility to fetch a model and pass it to the partial view that will be rendered and included at the place where you called this helper.