I'm using ASP.net MVC5 and I have the following:
[Route("Edit/{id}")]
[HttpGet]
public ActionResult Edit(int id)
{
// do stuff
return View(viewModel);
}
[Route("Edit")]
[HttpPost]
public ActionResult Edit(DraftViewModel draft)
{
if (!ModelState.IsValid) return View(draft);
// do stuff
return RedirectToAction("Index");
}
I expected this to produce pretty URLs like this:
Draft/Edit/5
instead I get this:
Draft/Edit?id=5
Why is this? How can I get pretty URLs with attribute based routing? The code that generates the link with the ugly URLs is this:
@Html.ActionLink("Edit", "Edit", "Draft", new { id = draft.Id }, new { @class = "btn btn-primary btn-xs" })
UPDATE
When I remove the [POST]
Action and only have [GET]
(not useful of course), the URL on the GET looks pretty! So it is when I have two routes of the same name (but different verbs) that the framework trips up!