3

我对 MVC 4 有点陌生,我的自定义路由有问题。我想在我的 URL 中使用斜杠 (/) 而不是问号 (?)。

这是我的代码:

地图路线:

routes.MapRoute(
    name: "Organisation",
    url: "{controller}/{action}/{startindex}/{begin}/{end}/{type}",
    defaults: new { controller = "Organisation", action = "getOrganisations" }
);

动作链接:

@Html.ActionLink("Organisation", "getOrganisations", "Organisation", new { startindex = 0, begin= "a", end= "f", type = "all" }, null)

我得到的网址:

http://localhost:1566/Organisation/getOrganisations?startindex=0&begin=a&end=f&type=all

我要的网址:

http://localhost:1566/Organisation/getOrganisations/0/a/f/all

解决方案

我找到了怎么做。这是如何:

@Html.RouteLink("Org","Organisation",new { startindex = 0, begin= "a", end= "f", type= "all" })

基本上,您可以使用将RouteLink路由名称和路由参数作为参数的 :)

编辑(贾斯汀)

  public ActionResult getOrganisations(int startindex, string begin, string end, string type)
    {
        List<'stored procedure'> retList= new List<'stored procedure'>();
        retList= Model.GetOrganisations(startindex, Convert.ToInt32(Request.Cookies["pagesize"].Value), begin, end, type);
        return View(retList);
    }
4

0 回答 0