我有一个ASP.Net MVC 4应用程序,我正在使用这样的Url.Action助手: @Url.Action("Information", "Admin")
此页面用于添加新的和编辑管理员配置文件.URL如下:
Adding a new: http://localhost:4935/Admin/Information
Editing Existing: http://localhost:4935/Admin/Information/5 <==Admin ID
Run Code Online (Sandbox Code Playgroud)
当我在Editing Existing网站的部分,并决定我想添加一个新的管理员时,我点击以下链接:
<a href="@Url.Action("Information", "Admin")">Add an Admin</a>
Run Code Online (Sandbox Code Playgroud)
但问题是上面的链接实际上是这样的http://localhost:4935/Admin/Information/5.只有在我编辑现有管理员的页面时才会发生这种情况.网站上的其他任何地方都能正确链接到http://localhost:4935/Admin/Information
有没有人见过这个?
更新:
RouteConfig:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud) 我遇到了一个我有默认MVC路由设置的场景.像所以.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
然后导航到这样的URL
domain/controller/action/1234
Run Code Online (Sandbox Code Playgroud)
在这个页面上,我然后导航到同一页面,但在某个事件之后使用不同的参数.像这样.
var id = $(this).data("id");
var url = "@Url.Action("action", "controller", new { area = ""})";
var params = $.param({id: id, vrnsearch: true});
var fullUrl = url += "?" + params;
window.location.href = fullUrl;
Run Code Online (Sandbox Code Playgroud)
我注意到url仍然在url中保持相同的id并附加参数.
domain/controller/action/1234?id=4321&vrnsearch=true
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,有没有办法确定优先权是否应该使用url或参数中的id值.
我实际上通过使用下面的方法找到了解决我的问题的方法,它从网址中删除了id并只使用了参数.
@Url.Action("action","controller", new {id = "", area = ""})
Run Code Online (Sandbox Code Playgroud)
但是,如果参数vs url路由中有优先权,那就太好奇了.