1

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();
}

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.