加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – ASP.NET MVC 3区域 – 无法使用自定义路由查找视

发布时间:2020-12-16 06:23:58 所属栏目:asp.Net 来源:网络整理
导读:我在一个区域有一条自定义路线如下: context.Routes.Add( "SearchIndex - By Location - USA",new CountryTypeSpecificRoute( CountryType.UnitedStates,"search/{locationType}-in-{query}",new { controller = "Search",action = "Index",query = UrlPara
我在一个区域有一条自定义路线如下:

context.Routes.Add(
                "SearchIndex - By Location - USA",new CountryTypeSpecificRoute(
                    CountryType.UnitedStates,"search/{locationType}-in-{query}",new { controller = "Search",action = "Index",query = UrlParameter.Optional },new { locationType = new UsaLocationSearchRouteConstraint() })
            );

示例网址:

/search/neighborhoods-in-new-york-city

解决行动很好.但它无法找到View.

The view ‘Index’ or its master was not found or no view engine
supports the searched locations. The following locations were
searched: ~/Views/Search/Index.cshtml
~/Views/Shared/Index.cshtml

该视图位于?/ Areas / Search / Views / Search / Index.cshtml中

为什么不看那里?

如果我docontext.MapRoute而不是context.Routes.Add,它的工作原理.所以它似乎与我使用自定义路线的事实有关?

有任何想法吗?

解决方法

由于 this answer解决了它

我制作了我的自定义路线工具IRouteWithArea(在ctor中取入),并相应地更新我的注册:

context.Routes.Add(
                "SearchIndex - By Location - USA",new { locationType = new UsaLocationSearchRouteConstraint() },"Search")
            );

请注意最后一个参数“搜索” – 表示区域名称.

不知道它是如何工作的,但确实如此.猜猜内部路由引擎查找实现IRouteWithArea的路由.

问题解决了!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读