goin back to my 'routes' - issue with partialviews and areas??

两盒软妹~` 提交于 2019-12-12 02:39:49

问题


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...



来源:https://stackoverflow.com/questions/6866866/goin-back-to-my-routes-issue-with-partialviews-and-areas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!