While writing code in MVC there are scenarios where you need to use one view in more than one action .
One way is to create separate view for it that will be a tedious process to do
Another way is to create a common view for multiple action
For doing that you need to write the method or action for it while selecting view you will make it a shared view
public class MenuController : Controller
{
[ChildActionOnly]
public ActionResult Header()
{
var model = ... // go to the database and fetch a model
return View("~/Views/Shared/_Header.cshtml", model);
}
}
You will return it wherever you want in your application
You will always create that view inside Shared folder which will make it sharable to other actions
0 Comment(s)