.NET MVC 4 routing

I'm a bit new to MVC 4 and I have a problem with my custom routing. I want to use forward slashes (/) in my URL instead of question marks (?).

This is my code:

MapRoute:

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

      

ActionLink:

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

      

Url:

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

      

URL I want:

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

      

Decision

I found how to do this. Here's how it's done:

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

      

Basically you can use RouteLink

which takes the route name and route parameters as parms :)

Edit (for Justin)

  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);
    }

      

+3


source to share





All Articles