I'm generating the list of links like this:
$('#latestNews').append('<li><a href="<%= Url.Action("Details", "Article") %>/' + key + '">' + val + '</a></li>');
And on the Index page link looks like:
<a href="/En/Article/Details/6">Title</a>
But, on the /En/Article/Details/6 page - generated link looks like:
<a href="/En/Article/Details/6/6">Title</a>
I've tried $('#latestNews').append('<li><a href="<%= Url.Action("Details", "Article") %>?id=' + key + '">' + val + '</a></li>'); It works ok, but then caching does not work.
My controller code:
[OutputCache(Duration = Int32.MaxValue, VaryByParam = "id,language", SqlDependency = "database:Articles")] //Articles will be added rarely so i think it'll be nice to cache them
public ActionResult Details(string id, string language)
{..}
My route:
routes.MapRoute(
"Default",
"{language}/{controller}/{action}/{id}",
new { language = "En", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
So how to generate Url in a better way?
UPDATED:
$.post('<%= Url.Action("GetLatest", "News") %>', function (data) {
$.each(data, function (key, val) {
$('#latestNews').append('<li><%= Url.ActionLink(val, "Details", "Article", new { id = key }, null) %></li>');
});
$('#news').show();
}, "json");