使用MapRoute mvc5

时间:2017-03-14 15:17:57

标签: c# razor asp.net-mvc-5 maproute

我是mvc5的新手,我不太了解如何形成干净的网址

现在我的RouteConfig.cs文件如下:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

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

我称之为:

@Url.Action("ListOrGrid", "ListOrGrid", new { id = cat.Categorie_Id, urlFormer = GlobalFunction.nomCategories(cat.Categorie_Id) })

函数GlobalFunction.nomCategories(short id)将表中类别的id转换为String

我的网址有以下格式:https://localhost:44375/ListOrGrid/ListOrGrid/12?urlFormer=Mode%2FFemmes%2FVetements%2FJupes

但我希望网址看起来像:https://localhost:44375/Mode/Femmes/Vetements/Jupes

我如何通过路线发送我的类别ID"分类"到控制器没有在网址中打印它,如"默认" MapRoute?

0 个答案:

没有答案