开发者

Html.Partial in Razor View Engine

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开发者_StackOverflow Controller:

public ActionResult GridControl()
{
   return PartialView();
}


Html.Partial doesn'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:

@Html.Action("GridControl")

or:

@{Html.RenderAction("GridControl");}

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜