I have a bunch of controller actions that return a View. Now I need to also return PartialView for each action because I want to make my assembly reusable in a parent application with parent views (I will use Html.Action in the parent View). It's a bit cumbersome to duplicate each action to return a partial view. Isn't there a cleaner way to disable the layout when nesting a controller action inside a parent view?
0
votes
1 Answers
2
votes
You can check ControllerContext.IsChildAction
in your action method and return a different view if it is true.
if (ControllerContext.IsChildAction)
{
return PartialView("_Index", model)
}
else
{
return View("Index", model)
}
If it makes sense for your application, load the partial view in your full view so that you can reuse the markup.