如何摆脱ASP.NET MVC路由中的问号? [英] How do I get rid of the question mark in an ASP.NET MVC route?

查看:72
本文介绍了如何摆脱ASP.NET MVC路由中的问号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了以下路线:

{theme}/{subtheme}/{contenttype}/{contentdetail}/Print

当我使用
Url.Action("PrintLayout","Page",新的{contentUrlTitle = Model.ContentUrlTitle}

我得到以下链接:

/theme1/subtheme1/contenttype1/myfirstcontenturltitle?action=PrintLayout 

我希望它是一个RESTful URL.

I'd like for it to be a RESTful URL.

/theme1/subtheme1/contenttype1/myfirstcontenturltitle/Print

你知道我在这里想念什么吗?

Do you know what im missing here?

推荐答案

由于您尚未发布路线表(提示:发布您的路线表),因此我不得不猜测路线是什么.如果您希望此方法有效,则路由必须为:

Since you haven't posted your routes Table (hint: Post your routes table), I'll have to guess as to what the route is. If you want this to work, the route needs to be:

routes.MapRoute("contentDetail",
    "{theme}/{subtheme}/{contenttype}/{contentdetail}/print"
    new { controller = "Page", action = "PrintLayout", theme="", subtheme="", contenttype = ""     
    });

然后是您的控制器:

public class PageController
{
    public ActionResult PrintLayout(string theme, string subtheme, string contenttype, string contentdetail)
    {
        //do print stuff here
    }
}

这篇关于如何摆脱ASP.NET MVC路由中的问号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆