我将下一个 MapRoute 添加到我的 RouteConfig 中:
routes.MapRoute(
name: "Noticias",
url: "{controller}/{action}/{id}/{urlAmiga}",
defaults: new
{
controller = "Noticias",
action = "Noticia",
id = "",
urlAmiga = ""
}
);
在视图中,我有下一个:
<a href="<%= Url.Action("Noticia","Noticias", new {id = item.IdNoticia, urlAmiga="this-is-a-test" }) %>">
<h5>
<%= item.Titulo %>
</h5>
</a>
控制器:
public ActionResult Noticia(int id)
{
var noticia = new NoticiaRepository().RecuperarNoticiaPorId(id);
ViewBag.IdNoticia = noticia.Id;
return View("Noticia", noticia);
}
我希望生成的链接看起来像:
http://www.domain/Noticia/1123/this-is-a-test
但是,结果是:
http://www.domain/Noticia?id=106532&urlAmiga=this-is-a-test
为什么?