-->

goin back to my 'routes' - issue with part

2019-08-30 01:26发布

问题:

i've hit another brick wall today with jquery generated partialviews when located within areas. it's a bit baffling as i have a number of partialviews located under ~/areas/administration/views/shared which all get rendered fine if included inside a normal view. However, if i invoke any of the same partial views via ajax, the controller action runs fine but i get an error. on closer inspection, the error reveals itself to be due to the partialview in question not being found by the view engine (ascx). basically, the console reports that all the 'normal' view locations were searched but that the engine was unable to find the view in question.

I'm wondering if it's a routing issue, tho it seems unlikely. has anyone else experienced an issue with partialviews inside areas when invoked via jquery ajax?? as i say, it's especially baffling given that the same partial renders just fine if included 'inline' in a standard view that 'lives' under the same areas folder.

thoughts welcome..

回答1:

Ok,

I got this fixed after a little brain-storming. Basically, the problem was related to the fact that I was referencing both the 'root' of the site and the 'areas' namespaces from the core web.config file, ie:

<pages>
  <namespaces>
    <add namespace="ABC.Web.Site.Controllers" />
    <add namespace="ABC.Web.Site.Models" />
    <add namespace="ABC.Web.Site.Models.ViewModels" />
    <add namespace="ABC.Web.Site.Areas.Administration.Controllers" />
    <add namespace="ABC.Web.Site.Areas.Administration.Models" />
    <add namespace="ABC.Web.Site.Areas.Administration.Models.ViewModels" />
  </namespaces>
</pages>

moving each set to their own web.config under the views folder sorted the issue: ie.:

root/views/web.config:

<pages>
  <namespaces>
    <add namespace="ABC.Web.Site.Controllers" />
    <add namespace="ABC.Web.Site.Models" />
    <add namespace="ABC.Web.Site.Models.ViewModels" />
  </namespaces>
</pages>

areas/views/web.config:

<pages>
  <namespaces>
    <add namespace="ABC.Web.Site.Areas.Administration.Controllers" />
    <add namespace="ABC.Web.Site.Areas.Administration.Models" />
    <add namespace="ABC.Web.Site.Areas.Administration.Models.ViewModels" />
  </namespaces>
</pages>

bliss...