0
我有一个Ajax.ActionLink在局部视图如下: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加载并更新整个页面 - 所以它的工作只要它的Ajax部分,但不管我做了什么,URL永远不会指向任何有用的地方 - 如实际的控制器和操作我已经指定。
我怎么通过ID成上的网址? –
将它添加为html属性,请参阅我的编辑 –