c# - Implicit connection of Action Methods with Views in ASP.NET MVC -
i working in brownfield asp.net mvc 3 project in vs2010.
in project, views , controllers in separate projects. not have seen before. in each action method there no explicit stating of view name below.
return view("viewname",passingmodel);//projects controllers , views in same
i have done implicitly in vs2012 right clicking on view , add view
. not bothered connection between action method's return view , view stated.
unlike in vs2012, in vs2010 can not navigate view related 1 particular action method right clicking on view , doing go view
.
i tried understand doing small experiment. created controller
, created action method
call xxxx
, created view implicitly mentioned above , searched word xxxx
in entire solution word appeared in controller , in view.
so, unsuccessful in finding answer. think visual studio creating own mapping achieve this. know these implicit connections created among action methods , views understand going on in project.
edit:
both projects contains controllers , views class libraries. not asp.net mvc projects.
global.aspx
file contains this:
public static void registerglobalfilters(globalfiltercollection filters) { filters.add(new handleerrorattribute()); } protected void application_start() { dependencieshelper.register(new httpcontextwrapper(context)); arearegistration.registerallareas(); registerglobalfilters(globalfilters.filters); routinghelper.registerroutes(routetable.routes); } protected void application_end() { //should close index //if method not executed, search engine still work. searchservice.closeindex(); }
the mapping straightforward. example if have controller called "mybrilliantcontroller" , action method called "myexcellentaction" returned return view();
map (in ui project) ~/views/mybrilliant/myexcellentaction.cshtml
the time different when working "areas" - mapping same, consider area folder first (ie ~/areas/myarea/views/mybrilliant/myexcellentaction.cshtml
)
hope helps.
edit - can specify namespaces in global.asax file on each route engine find controllers
public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( "default", // route name "{controller}/{action}/{id}", // url parameters new { controller = "home", action = "index", id = urlparameter.optional }, // parameter defaults new string[] { // namespaces in find controllers route "mysolution.mycontrollerslib1.helpers", "mysolution.mycontrollerslib2.helpers", "mysolution.mycontrollerslib3.helpers" } ); }
Comments
Post a Comment