mvc Can i have one view for multiple action methods to target? or do i need a separate view for each?

multiple actions from a single view page in mvc 5
mvc multiple views on same page
perform list, insert update and delete in a single view in asp net mvc
submit mvc form and show results on the same page
one view multiple controllers mvc
actionresult stay on the same page
mvc list and create in same view
how to return same view mvc

I have set up a menu-controller to drive the top menu links based on which other controller is being used. Each other controller has a separate nested master page for each of its views.

so, i have a menu-controller with several methods that return viewresults, one per each controller, or "section" of the site. So currently each of these methods has its own view to render the menu. but each view to render the menu is the same code, the only thing that changes is the logic in the controller methods based on which links to render.

is there any way to have all of these controller actions target the same view? since the view is the same for all?


Yes, that is a common practice.

return View("Menu"); mvc Can i have one view for multiple action methods to , Each other controller has a separate nested master page for each of its actions target the same view? since the view is the same for all? Here Mudassar Ahmed Khan has explained with an example, how to use multiple Action methods of same Controller in Same Page (View) in ASP.Net MVC Razor. This article will illustrate how to post (send data) to multiple Action methods of same Controller in ASP.Net MVC Razor.

Create a strongly typed view that takes a container specifying your menu content. Pass this as a parameter on your return statement.

 var thisMenu = CreateMenuForThisRequest();
 return View ("Menu", thisMenu); mvc Can i have one view for multiple action methods, The scenario is as follows; i.e., create a single page, which will NET MVC platform only attaches a single model to a single view, Today, I shall be demonstrating about how to utilize multiple view models into a single view in an ASP. and replace the code given below in each file accordingly, as shown  MVC is the Model View Controller Design Pattern. Design Pattern depends on multiple views and controllers can interface with the same model. Where my thought is that a method is responsible for a view page. Normally methods like Index, Details, Create, Edit and Delete are responsible for a single web page for each of them.

it depends on what version of ASP MVC you're using; with MVC 2, you can create an ascx control and use RenderAction

in your view you'll put something like

Html.RenderAction("Menu", "Navigation");

and have a navigation controller with a Menu actionresult

public class NavigationController : Controller
      public ActionResult Menu()
        Menu model;//your menu
        return PartialView("YourMenuAscxControlName", model);

I think if you're using MVC 1, the MVC Future project has the RenderAction but i'm not sure.

ASP.NET MVC 5 - Multiple View Models In Single View, Partial view is a reusable view, which can be used as a child view in multiple If a partial view will be shared with multiple views of different controller folder Let's have an overview of each method and then see how to render partial The specified Action method should return PartialViewResult using the Partial() method. For ASP.NET MVC beginner, it is very common problems that they faces in programming world: That how they can use multiple Models in their ASP.NET MVC application’s view. Some of beginners is familiar with some of way to use multiple Models in an ASP.NET MVC application. But, May be they are not know about all the way to use Multiple Models in ASP.NET MVC.

For my menu I use the RenderAction method I'm also using the ActionOutputCacheAttribute from Steve Sanderson

you will greatly increase your site loading time with this caching

Partial View in ASP.NET MVC, ASP.NET MVC introduced Layout view which contains these common UI The layout view is same as the master page of the ASP. which can be inherited in multiple views to provide a consistent look and feel in multiple pages of an application. in the individual view or specifying layout view name in the action method. There are many ways to use multiple models with a single view. Here I will explain ways one by one. 1. Using Dynamic Model. ExpandoObject (the System.Dynamic namespace) is a class that was added to the .Net Framework 4.0 that allows us to dynamically add and remove properties onto an object at runtime.

Layout View in ASP.NET MVC, NET MVC to discover what parts to use, what parts to avoid, and how to get the most Trivial applications often do not need this pattern, but CodeCampServer is an Instead of putting this repeated data access code in all of our actions, we can The other option is to create a separate view model type for our views from​  In MVC we cannot use multiple model tag on a view. But Many times we need to pass multiple models from controller to view or we want to show data from multiple model on a view.

Chapter 12. Best practices, Getting Started with ASP. NET Core MVC with controllers and views. Controller methods (also known as action methods), such as the Index of your site in one place and then apply it across multiple pages in your site. defines the common layout that all views will use, therefore you can comment out  Since we know the constraint on ASP.NET MVC platform i.e. we can only attach a single model to a single view. So, here we will create a parent place holder kind of model; i.e., Common Model, and make our actual view models the child to this model, as shown below Step 3

Adding a View to an MVC app, cshtml file to each view. The Layout property can be used to set a different layout view, or set it to null so no layout file will be used. In ASP.NET MVC applications we need to use multiple submit buttons on single view to achieve certain functionalities, and if we create a view from model that is a strongly typed view, then by default view behavior is submitted and it adds many functionalities. While submitting the form it will fire the validation.

  • MVC Future for MVC 1 has the RenderAction