0

The Html.ActionLink

<li> ${Html.ActionLink<HomeController>(c => c.Edit(ViewData.Model.Id, ViewData.Model.Title), "Edit")} </li>

When created as html shows the URL to be Edit/5006?title=One . How do I change this to a pretty URL like Edit/5006/One ?

My Edit Action method is

public ActionResult Edit(int id, string title) 
DaveRandom
  • 87,921
  • 11
  • 154
  • 174
Quintin Par
  • 15,862
  • 27
  • 93
  • 146

3 Answers3

2

You need to have a route setup:

routes.MapRoute(
    "DefaultWithTitle",
    "{controller}/{action}/{id}/{title}",
    new 
    { 
        controller = "Home", 
        action = "Edit", 
        id = UrlParameter.Optional,
        title = UrlParameter.Optional
    }
);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

It is not depends on the function stamp, but it depends on the routing configuration.

routes.MapRoute("Edit",                                         // Route name
        "{controller}/{action}/{id}/{title}",                   // URL with parameters 
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults 
); 
Fitzchak Yitzchaki
  • 9,095
  • 12
  • 56
  • 96
0

Take a look at the first answer to this question: HTML.ActionLink method

The important point is that you have to make sure you're using the right overload for ActionLink().

Community
  • 1
  • 1
Dave Swersky
  • 34,502
  • 9
  • 78
  • 118