如何将/关于路线/转到/关于 [英] How to Route /About to /Home/About

查看:65
本文介绍了如何将/关于路线/转到/关于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用ASP.NET MVC,这太好了!但是,我不太了解设置路线.

I am just getting started with ASP.NET MVC and it's great! However, I don't quite understand setting up routes.

如何将〜/About路由到〜/Home/About?

How do I route ~/About to ~/Home/About?

/Views/Home/About.aspx

/Views/Home/About.aspx

我希望能够通过 /主页/关于 要不就 /关于

I would like to be able to access it with /Home/About or just /About

推荐答案

如果要为其明确设置路由,可以执行以下操作:

If you want to explicity setup a route for it, you can do something like this:

routes.MapRoute( 
            "AboutRoute", 
            "About", 
            new { controller = "Home", action = "About" }  // Parameter defaults 
    );

我认为这就是您想要做什么? IE.家用控制器处理了/About吗?

I think thats what you want to do? I.e. have /About handled by the home controller?

默认路由(如下所示)处理/Home/About

The default route (as below) handles /Home/About

    routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

这篇关于如何将/关于路线/转到/关于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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