asp.net mvc 3 - mvc 3 razor view engine using "default" views -


i'm using razor new project in company, , have been playing 2 days , found weird behaviour imho.

i have home controller in root of webapp , home controller in area , call area1. in both these controllers have index action , therefore got index view in views root folder, , 1 in area1\views folder. if remove index view within area , area1\views\index.cshtml , request area1\home\index, don't error view engine not finding view action , "base" index view found in \views\index.cshtml , rendered.

someone knows if bug or it's done purpose ? if so, there's way disable default ?

definitely not bug.

this behaviour allows easy reuse of view templates, eg, error handling.

the default behaviour asp.net mvc if do...:

return view(); 

...it searches view template name of action use in number of places: default naming convention folder controller, ie, /area1/views/home/, /area1/views/shared/ area1/views/ /views/shared/ /views/

if finds no such view matching name of action, throws error.

so default behaviour. "customize" behaviour, need following:

in controller actions, can specify name of view template use when return. eg:

return view("myotherview"); 

or better still, if using t4mvc:

return view(mvc.area1.home.views.myotherview);  // away "magic" strings 

as result, don't see need switch off default behaviour able (whatever) want. controllers there to, uhmmmm, control views used display user. best practice.

however, asp.net mvc configurable, there ways , means, presume, switch off.

if want this, luck you, makes more sense follow defaults , understand how asp.net mvc works, if beginner.

note:

the above applies asp.net mvc 1, 2, 3 , continue so. default behaviour view engines, including razor , webform views.

ps:

and can configure urls using route registration if concern of url in user's browser.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -