回到我的“路线"-有关局部视图和区域的问题?? [英] goin back to my 'routes' - issue with partialviews and areas??

查看:56
本文介绍了回到我的“路线"-有关局部视图和区域的问题??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,当我位于区域内时,jquery生成了局部视图,这又碰到了另一堵墙.这有点令人困惑,因为我在〜/areas/administration/views/shared下有许多partialviews,如果包含在普通视图中,所有这些partialviews都会很好地呈现.但是,如果我通过ajax调用任何相同的局部视图,则控制器操作运行良好,但出现错误.在仔细检查后,该错误显示出自己是由于视图引擎(ascx)找不到相关的局部视图而导致的.基本上,控制台报告已搜索了所有正常"视图位置,但引擎无法找到有问题的视图.

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.

我想知道这是否是路由问题,似乎不太可能.通过jquery ajax调用时,其他人在区域内是否遇到过局部视图问题?就像我说的那样,尤其令人困惑的是,如果将内联"包含在存在于"同一区域文件夹下的标准视图中,则相同的部分渲染就可以了.

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.

表示欢迎.

推荐答案

好,

经过一番脑力激荡,我解决了这个问题.基本上,该问题与以下事实有关:我同时引用了站点的根"和核心web.config文件中的区域"命名空间,即:

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>

将每个集合移动到views文件夹下的自己的web.config可以对问题进行排序:即:

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

root/views/web.config:

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:

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>

幸福...

这篇关于回到我的“路线"-有关局部视图和区域的问题??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆