【发布时间】:2014-02-07 23:02:31
【问题描述】:
我在部分视图中有一个 Ajax.ActionLink,如下所示:
<div id="accordion">
@foreach (var m in Model)
{
var targetId = m + "_List";
<h3 id="@(m)" class="thingModelHeader">
@Ajax.ActionLink(m, "AjaxGetThings", "Perf",
new AjaxOptions {
HttpMethod="GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId= targetId,
Url="13412"
})
</h3>
<div id="@targetId" >
@* list will populate here when the link is clicked *@
</div>
}
</div>
我有一个使用适当方法的控制器:
public class PerfController : Controller
{
[Route("AjaxGetThings/{id}", Name = "AjaxGetThings")]
public PartialViewResult AjaxGetThings(string id)
{
IQueryable<Thing> results;
using (var repo = new ReadOnlyRepository<Thing>())
{
things = repo.All()
.Where(p => p.Id == Id)
.OrderBy(p => p.Name)
;
}
return PartialView("CustomPartialView", results);
}
}
我有一个用于不显眼验证的 ScriptBundle:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
...我在我的布局页面中引用它:
</footer>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jquery-ui")
@Scripts.Render("~/bundles/jqueryval")
@RenderSection("scripts", required: false)
</body>
</html>
问题在于,无论我如何在 AjaxOptions 中定义 Action、Controller 或 Url,链接始终指向当前 URL。目标 div 加载和更新整个页面的 'nuther 版本 - 所以它 工作 就其 Ajax 部分而言,但无论我做什么,URL 永远不会指向任何有用的地方 - 比如我指定的实际控制器和操作。
【问题讨论】:
标签: javascript jquery ajax asp.net-mvc-4