【发布时间】:2011-08-21 01:05:11
【问题描述】:
我正在生成这样的链接列表:
$('#latestNews').append('<li><a href="<%= Url.Action("Details", "Article") %>/' + key + '">' + val + '</a></li>');
在索引页面上的链接看起来像:
<a href="/En/Article/Details/6">Title</a>
但是,在 /En/Article/Details/6 页面上 - 生成的链接看起来像:
<a href="/En/Article/Details/6/6">Title</a>
我试过$('#latestNews').append('<li><a href="<%= Url.Action("Details", "Article") %>?id=' + key + '">' + val + '</a></li>');它工作正常,但缓存不起作用。
我的控制器代码:
[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)
{..}
我的路线:
routes.MapRoute(
"Default",
"{language}/{controller}/{action}/{id}",
new { language = "En", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
那么如何更好的生成Url呢?
更新:
$.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");
【问题讨论】:
标签: jquery asp.net-mvc caching url-rewriting