nevernome
nevernome

Reputation: 25

Controller for a PartialView

I am Creating a new partial view in MVC 3 as this functionality is required through out my application.Is it possible to have a separate controller for my partial view only

Upvotes: 1

Views: 65

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236208

Yes, you can. Create controller (consider to disable non-child action calls if you need to use controller only for partial view):

public class FooController : Controller
{
    [ChildActionOnly]
    public PartialViewResult Bar()
    {
        var model = new BarModel();
        return PartialView("_Bar", model);
    }
}

And use it

@Html.RenderAction("Bar", "Foo")

Upvotes: 1

Related Questions