MapRouting默认查询字符串值? [英] MapRouting default querystring values?

查看:146
本文介绍了MapRouting默认查询字符串值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个路线图(请注意,topicName被忽略):

I have this route map (notice that topicName is ignored):

routes.MapRoute(
                "Topics", // Route name
               "Topic/{topicName}/{action}",
                new { controller = "Topic", action = "AddQuestion" });  

和我希望它defaultly映射到以下链接:
的http://本地主机:51421 /主题/ SomeName / AddQuestion topicId = 1 (如果这是不可能的,这个网址:的http://本地主机:51421 /主题/ SomeName / AddQuestion / topicId / 1 )结果
(这应该调用这个动作:

And I want it to defaultly map to this Url: http://localhost:51421/Topic/SomeName/AddQuestion?topicId=1 (or if that's not possible,to this url: http://localhost:51421/Topic/SomeName/AddQuestion/topicId/1)
(which should invoke this action:

public ActionResult AddQuestion(int topicId)
        {
            return View();
        }  

)结果
但无论哪种方式,我需要在URL中所有数据。结果
什么是做到这一点的正确方法?

)
But either way I need all this data in the url.
What's the correct way to do that?

推荐答案

您可以添加一个默认的路由:

You could add a default route:

routes.MapRoute(
    "Topics",
    "Topic/{topicName}/{action}/{topicId}",
    new { controller = "Topic", action = "AddQuestion", topicId = "1" }
);

routes.MapRoute(
    "Default",
    "{controller}/{action}/{topicId}",
    new { controller = "Topic", action = "AddQuestion", topicId = "1" }
);

这篇关于MapRouting默认查询字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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