更改MVC中的操作网址 [英] Change URL of action in mvc
问题描述
是否可以在mvc中更改给定操作的URL,而无需更改所调用的操作或控制器?
Is there a way to change the URL of a given action in mvc without changing the action or controller called?
如果是这样,将如何在以下MapRoute上完成此操作:
If so, how would this be done on the following MapRoute:
routes.MapRoute(
"Estate.CloseDeal",
"Estate/CloseDeal/{groupId}/{paymentType}/{mortgageValue}/{province}",
new { controller = "Estate", action = "CloseDeal" },
new { groupId = "\\d+", paymentType = "\\d+", mortgageValue = "\\d+", province = "\\d+" }
);
所需的URL是:".../estate-support/deal-closing/...".当前显示为".../Estate/CloseDeal/..."
The desired URL is: ".../estate-support/deal-closing/...". Currently it displays as ".../Estate/CloseDeal/..."
链接到此操作的按钮如下:
The button linking to this action looks like:
<button detail="@Url.Action("CloseDeal", new { groupId = info.GroupId })" class="orange">
尝试更改为:
routes.MapRoute(
"Estate.CloseDeal",
"estate-support/deal-closing/{groupId}/{paymentType}/{mortgageValue}/{province}",
new { controller = "Estate", action = "CloseDeal" },
new { groupId = "\\d+", paymentType = "\\d+", mortgageValue = "\\d+", province = "\\d+" }
);
此返回的错误:您正在查找的资源已被删除,名称已更改或暂时不可用.
This returned error: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
更改第二个字符串适用于所有路线,但这一路线除外-区别在于,此路线具有其他参数(groupID,paymentType等).
Changing the second string worked for all routes but this one - the difference being, this route has additional parameters (groupID, paymentType etc.).
推荐答案
只需将第二个字符串中的"Estate/CloseDeal"
替换为"estate-support/deal-closing"
-应该可以正常工作.
Just replace "Estate/CloseDeal"
in the second string with "estate-support/deal-closing"
- should work fine.
在这种特殊情况下,这很容易,因为没有在控制器和动作名称上对路由进行参数设置-即,路由中没有"{controller}/{action}"
.
In this particular case it's this easy because the route is not parameterised over the controller and action names - i.e. the route doesn't have "{controller}/{action}"
in it.
这篇关于更改MVC中的操作网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!