kala-tamin How to define route & controller structure for 2 controllers?


How to define route & controller structure for 2 controllers?



I want to create an MVC app to generate factsheets, but I'm not sure how to structure the routing and controllers.

It consists of an index page, which acts as a template for the layout of a number of independent panels, each of which contains different types of data.

I want to have a the route template like the following:

/Factsheets/Panels/PanelType?fundId=1&countryId=ABC 

so these would be the URLs I'm using:

/Factsheets/Panels/NameAndDatePanel?Afund=1&county=IE   /Factsheets/Panels/AssetsPanel?fund=1&county=IE 

I want a Factsheets controller to be able to supply the Panel controller with the configuration object it needs to generate the type of panel I request.

What should my routing structure look like?

What should my controller structure look like?

edit:

What changes if I want to have a roure structure as follows:

I want to have a the route template like the following:

/Factsheets/ContentArea/Panels/PanelType?fundId=1&countryId=ABC 

so these would be the URLs I'm using:

/Factsheets/PageTop/Panels/NameAndDatePanel?Afund=1&county=IE   /Factsheets/PageTop/Panels/AssetsPanel?fund=1&county=IE 

so that FactsheetsController is instantiated to contain the data needed by a ContentArea to know which data to supply to the panel it needs to generate.




Add another propertymapping? (AutoMapper)

1:



Help with asp.net mvc 1.0 or 2 in Visual Studio 2010
What comes after the ? is the query string so it won't be reflected by the routing engine.


How many files are too many in an ASP.NET MVC project?
So your route might look like this:.
asp.net mvc 2.0 Jquery form submit
routes.MapRoute(     "Default",     "{controller}/{action}/{panelType}",     new { controller = "Factsheets", action = "Panels", panelType = UrlParameter.Optional } ); 
And you would have the following controller:.
Pulling a View from a database rather than a file
public class FactsheetsController : Controller {     public ActionResult Panels(string panelType)     {         return View();     } } 
UPDATE:.
When is it ok to meddle in the page lifecycle an ASP.NET MVC page?
If the panelType parameter is not optional you could provide a regex constraint:.
Significant advantages of ASP.NET MVC
routes.MapRoute(     "Default",     "Factsheets/Panels/{panelType}",     new { controller = "Factsheets", action = "Panels", panelType = UrlParameter.Optional },     new { panelType = ".+" } ); 


ASP.NET MVC application fires Session_Start multiple times for a single session


89 out of 100 based on 49 user ratings 1199 reviews