Asp.net mvc 如何消除ASP.NET MVC路线中的问号?
我定义了以下路线:Asp.net mvc 如何消除ASP.NET MVC路线中的问号?,asp.net-mvc,model-view-controller,Asp.net Mvc,Model View Controller,我定义了以下路线: {theme}/{subtheme}/{contenttype}/{contentdetail}/Print 当我使用 Url.Action(“打印布局”,“页面”,新建{contenturltTitle=Model.contenturltTitle} 我得到以下链接: /theme1/subtheme1/contenttype1/myfirstcontenturltitle?action=PrintLayout 我希望它是一个RESTful URL /theme1/s
{theme}/{subtheme}/{contenttype}/{contentdetail}/Print
当我使用Url.Action(“打印布局”,“页面”,新建{contenturltTitle=Model.contenturltTitle}
我得到以下链接:
/theme1/subtheme1/contenttype1/myfirstcontenturltitle?action=PrintLayout
我希望它是一个RESTful URL
/theme1/subtheme1/contenttype1/myfirstcontenturltitle/Print
你知道我遗漏了什么吗?我想你可以试试这个:
Url.Action("PrintLayout/Print", "Page");
问题是,当您使用字典解析新参数时,默认行为就是这样。由于您尚未发布路由表(提示:发布路由表),我将不得不猜测路由是什么。如果您希望这样做,路由需要:
routes.MapRoute(“contentDetail”,
“{theme}/{subtheme}/{contenttype}/{contentdetail}/print”
新建{controller=“Page”,action=“printloayout”,theme=“”,subtheme=“”,contenttype=“”
});
然后您的控制器:
public class PageController
{
public ActionResult PrintLayout(string theme, string subtheme, string contenttype, string contentdetail)
{
//do print stuff here
}
}
Jose3d
Url.Action ("PrintLayout","Page",new {contentUrlTitle = Model.ContentUrlTitle}
将为路线匹配提供以下参数:
controller=“Page”,action=“PrintLayout”,contentUrlTitle=“{Model.contentUrlTitle}的值”
正如您在这里看到的,'controller'和'action'参数由ASP.NET MVC隐式定义
我不明白的一件事是,为什么“controller”参数不同时显示为查询字符串?也许提供更多详细信息会更有帮助。能否为整个路由添加代码。MapRoute代码?