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) 
1

3 Answers 3

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
    }
);
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.