路由难度
我的应用程序的一部分将存储在多个位置的资源映射到 Web URL,如下所示:
http://servername/Issue.aspx/Details?issueID=1504/productId=2345
是否可以构造一个与此匹配的 MVC 路由,以便我将完整的路径传递到我的控制器中?可以作为单个字符串,也可以作为 params 样式的字符串数组。
在我的 Global.aspx 中我有 路线.MapRoute( “问题”, “问题/{详细信息}”, new {controller =“问题”,action =“详细信息”}, 新 { 问题 ID = @"\d+", 产品 ID = @"\d+" } );
我已经尝试过代码
RouteValueDictionary parameters = new RouteValueDictionary { {"Controller", "Issue"},{ "action", "Details" }, { "issueId", Test.ID }, {"productId", Test.Project.ID} };
VirtualPathData vpd = RouteTable.Routes.GetVirtualPath(null, parameters);
var test = vpd.VirtualPath;
测试值是
/Issue.aspx/Details?issueId=1504&productId=3625。
如何使用 ASP.NET 路由生成 URL 并将其发送给用户,他们应该能够通过单击生成的链接来打开页面。但是,这里不包括服务器名称。如何获得链接为 http://servername/Issue 的服务器名称.aspx/详细信息?issueID=1504/productId=2345
Part of my application maps resources stored in a number of locations onto web URLs like this:
http://servername/Issue.aspx/Details?issueID=1504/productId=2345
Is it possible to construct an MVC route that matches this so that I get the path in its entirety passed into my controller? Either as a single string or possibly as an params style array of strings.
In my Global.aspx I haveroutes.MapRoute(
"Issue",
"Issue/{Details}",
new { controller = "Issue", action = "Details" },
new { issueId = @"\d+", productId = @"\d+" }
);
I have tried the code
RouteValueDictionary parameters = new RouteValueDictionary { {"Controller", "Issue"},{ "action", "Details" }, { "issueId", Test.ID }, {"productId", Test.Project.ID} };
VirtualPathData vpd = RouteTable.Routes.GetVirtualPath(null, parameters);
var test = vpd.VirtualPath;
test value is
/Issue.aspx/Details?issueId=1504&productId=3625.
How to generate URLs Using ASP.NET Routing and sends it to users and they should be able to open the page by clicking on the generated link. However, here the servername isn`t included. How can I have the servername with the the link as http://servername/Issue.aspx/Details?issueID=1504/productId=2345
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您错误注册了路线。
Issue/{Details}
构建一个名为Details
的参数,并提供您在 url 中的Issue/
之后输入的值。我猜你应该删除大括号。理想情况下,我认为您应该编写如下内容:
如果您正确设置了路线,请使用它在视图中生成链接,
它将生成类似的内容
我推荐 这本书如果你想更好地了解 ASP.NET MVC 平台。我这周只读了一次,就能够回答这个问题了。
First of all you misregistered the route.
Issue/{Details}
builds a parameter calledDetails
, and gives a value you enter afterIssue/
in your url. I am guessing you should remove the curly brackets.Ideally, I think you should write something like this:
If you have the route set up correctly, use this to generate the link in your View
it will generate something like this
I recommend this book if you want to know the ASP.NET MVC platform better. I've only read it once this week and I was able to answer this.
http://weblogs.asp.net/srkirkland/archive/2009/09/17/a-urlhelper-extension-for-creating-absolute-action-paths-in-asp-net-mvc.aspx