asp.net-mvc – ASP.NET MVC4路由问题
发布时间:2020-05-25 10:43:33 所属栏目:asp.Net 来源:互联网
导读:我已经搜索了Stack多年,阅读了MSDN文档并使用了Bing,但是看不出为什么这不起作用!我在路线下面有相关的代码.名为Browse的路由工作得很好,但Details路由的productCode参数总是等于零.如果我制作任何mods,我会继续获得“找不到资源”404页面. Lives in control
|
我已经搜索了Stack多年,阅读了MSDN文档并使用了Bing,但是看不出为什么这不起作用!我在路线下面有相关的代码.名为Browse的路由工作得很好,但Details路由的productCode参数总是等于零.如果我制作任何mods,我会继续获得“找不到资源”404页面. ' Lives in controller called 'Details' ' Usage: site.com/details/abc123 Function Index(productCode As String) As ActionResult ' Lives in controller called 'Browse' ' Usage: site.com/browse/scifi/2 Function Index(genre As String,Optional page As Integer = 1) As ActionResult 路线是: routes.MapRoute( _
"Browse",_
"{controller}/{genre}/{page}",_
New With {.controller = "Browse",.action = "Index",.id = UrlParameter.Optional,.page = UrlParameter.Optional}
)
routes.MapRoute( _
"Details",_
"details/{productCode}",_
New With {.controller = "Details",.action = "Info",.productCode = UrlParameter.Optional}
)
解决方法订单在定义路线时很重要.当您请求site.com/details/abc123时,我认为它与您的第一条路线相符. 你会得到 controller =“details” action =“索引” genre =“abc123” 这就是您的productCode为空的原因. 切换两个route.MapRoute语句,它应该解决你的问题. 你的第二条路线确实将动作设置为信息而不是索引,但我假设这是一个错字? (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – ELMAH登录SQL Server
- asp.net-mvc – ASP.NET MVC – 值类型的自定义验证消息
- asp.net – App Settings和connectionStrings配置设置中连接
- ASP.NET MVC发布模型ID的更好方法是什么?
- asp.net – 我怎么知道我的应用程序中是否需要“WCF HTTP激
- asp.net – 什么是动词=“*”?
- asp.net-mvc – 动作命名约定
- asp.net-mvc – ASP.NET MVC中的Crystal Reports
- asp.net – web.config文件设置是否覆盖IIS设置?
- asp.net – 如何使用PSAKE发布网站
推荐文章
站长推荐
热点阅读
