MVC 4移除];家"从基本路线 [英] MVC 4 Remove "home" from base route

查看:127
本文介绍了MVC 4移除];家"从基本路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想要让这个:
http://website.com/Home/About

Basically I want to make it so that: http://website.com/Home/About

显示为:
http://website.com/About

家的控制器上显示的是网址将使URL再为用户阅读。

The "home" controller showing up in the url would make the url longer for the user to read.

我试着做到以下几点:

routes.MapRoute(
            name: "About",
            url: "",
            defaults: new { controller = "Home", action = "About", id = UrlParameter.Optional }
            );

有人能帮助我吗?

Could someone help me out please?

推荐答案

尝试是这样的:

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "OnlyAction",
        "{action}",
        new { controller = "Home", action = "Index" } 
    );

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

这篇关于MVC 4移除];家"从基本路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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