asp.net mvc - How to change View & partial view default location -


i new in mvc , curious know how change view & partial view location.

we know view & partial view store in view folder. if controller name home view must store in home folder inside view folder , parial view store in shared folder. know how can change view & partial view default location ?

1) suppose controller name product want store corresponding view in myproduct folder.......guide me need make works fine.

2) want store partial view in partial folder inside view folder , want load partial view there. guide me need make works fine.

basicall how instruct controller load view & partial view folder without mentioning path. looking discussion. thanks

you can modify razorviewengine's viewlocationformats , partialviewlocationformats properties in global.asax startup code. around lines below should work:

protected void application_start(object obj, eventargs e) {    var engine = viewengines.engines.oftype<razorviewengine>().single();    var newviewlocations = new string[] {         "~/someotherfolder/{1}/{0}.cshtml",         "~/globalfolder/{0}.cshtml"          };    engine.viewlocationformats = newviewlocations;    engine.partialviewlocationformats = newviewlocations; } 

iirc, {1} correspond controller , {0} view name, can @ existing properties make sure.

if want keep existing search locations need copy them new array.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -