c# - ASP.NET MVC - Views location Issue: The view 'Index' or its master was not found -
i've create asp.net mvc 2 project, works fine!!
i've been asked integrate project in existing web project in classic asp.net
(i've add folder containing source, , not make new project, because have bee in same project)
i've configured web.config
file
<pages pagebasetype="system.web.ui.page" > <controls> <add tagprefix="asp" namespace="system.web.ui" assembly="system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" /> <add tagprefix="asp" namespace="system.web.ui.webcontrols" assembly="system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" /> </controls> <namespaces> <add namespace="system.web.mvc" /> <add namespace="system.web.mvc.ajax" /> <add namespace="system.web.mvc.html" /> <add namespace="system.web.routing" /> <add namespace="system.linq" /> <add namespace="system.collections.generic" /> <add namespace="searchapp.helpers.checkboxlist"/> <add namespace="searchapp.helpers.pager"/> </namespaces> </pages> <httpmodules> <add name="scriptmodule" type="system.web.handlers.scriptmodule, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" /> <add name="urlroutingmodule" type="system.web.routing.urlroutingmodule, system.web.routing, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" /> </httpmodules> <!--- end mvc config section-->
and global.asax
file (i'm working under iis 5.1) :
public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( "searchapp", // route name "searchapp/{controller}.aspx/{action}/{id}", // url parameters new { controller = "search", action = "index", id = "" } // parameter defaults ); } protected void application_start(object sender, eventargs e) { arearegistration.registerallareas(); registerroutes(routetable.routes); }
the hierarchy of project (i can’t find how insert image in post):
+project ++mvc2appfolder +++controller ++++searchcontroller.cs +++views ++++search +++++index.aspx ++global.asax ++web.config
as can see global.asax
not in mvc app folder
when try access page search/index.aspx using url http://localhost/cstfwsrv/searchapp/search.aspx/index[^] have following error :
i
the view `index` or master not found. following locations searched: ~/views/search/index.aspx ~/views/search/index.ascx ~/views/shared/index.aspx ~/views/shared/index.ascx description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code. exception details: system.invalidoperationexception: view 'index' or master not found. following locations searched: ~/views/search/index.aspx ~/views/search/index.ascx ~/views/shared/index.aspx ~/views/shared/index.ascx source error: unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using exception stack trace below. stack trace: [invalidoperationexception: view 'index' or master not found. following locations searched: ~/views/search/index.aspx ~/views/search/index.ascx ~/views/shared/index.aspx ~/views/shared/index.ascx] system.web.mvc.viewresult.findview(controllercontext context) +253553 system.web.mvc.viewresultbase.executeresult(controllercontext context) +139 system.web.mvc.controlleractioninvoker.invokeactionresult(controllercontext controllercontext, actionresult actionresult) +10 system.web.mvc.<>c__displayclass14.<invokeactionresultwithfilters>b__11() +20 system.web.mvc.controlleractioninvoker.invokeactionresultfilter(iresultfilter filter, resultexecutingcontext precontext, func`1 continuation) +251 system.web.mvc.<>c__displayclass16.<invokeactionresultwithfilters>b__13() +19 system.web.mvc.controlleractioninvoker.invokeactionresultwithfilters(controllercontext controllercontext, ilist`1 filters, actionresult actionresult) +178 system.web.mvc.controlleractioninvoker.invokeaction(controllercontext controllercontext, string actionname) +314 system.web.mvc.controller.executecore() +105 system.web.mvc.controllerbase.execute(requestcontext requestcontext) +39 system.web.mvc.controllerbase.system.web.mvc.icontroller.execute(requestcontext requestcontext) +7 system.web.mvc.<>c__displayclass8.<beginprocessrequest>b__4() +34 system.web.mvc.async.<>c__displayclass1.<makevoiddelegate>b__0() +21 system.web.mvc.async.<>c__displayclass8`1.<beginsynchronous>b__7(iasyncresult _) +12 system.web.mvc.async.wrappedasyncresult`1.end() +59 system.web.mvc.mvchandler.endprocessrequest(iasyncresult asyncresult) +44 system.web.mvc.mvchandler.system.web.ihttpasynchandler.endprocessrequest(iasyncresult result) +7 system.web.callhandlerexecutionstep.system.web.httpapplication.iexecutionstep.execute() +8677678 system.web.httpapplication.executestep(iexecutionstep step, boolean& completedsynchronously) +155
as can see search index.aspx page under ~/views/search/index.aspx
, wich under ~/mvc2appfolder/views/search/index.aspx
is there way set in route method, or else, view path?
thanks’ in advance
you can create own viewengine in right place find view. prepend ~/mvc2appfolder/{0} before view path.
since you're using mvc2, might want see post phil haack mvc2 areas: http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx
Comments
Post a Comment