ASP.NET MVC 3(剃刀)Ajax.ActionLink - 我究竟做错了什么? [英] ASP.NET MVC 3 (Razor) Ajax.ActionLink - What am i doing wrong?
问题描述
想有点击它时,应该做一个AJAX动作链接 HTTPGET
来返回一个动作方法 PartialViewResult
并且推HTML到一个div。
Trying to have a AJAX action link which when clicked, should do a HttpGet
to an action method which returns a PartialViewResult
and shoves the HTML into a div.
下面是我的看法:
<div id="admin-options" class="admin"></div>
@Ajax.ActionLink("Show Admin Options", "ShowOptions", "Post", new { area = "Admin" }, new AjaxOptions { UpdateTargetId = "admin-options", HttpMethod = "GET" })
下面是操作方法:
public class PostController : Controller
{
[HttpGet]
[Authorize(Roles="Admin")]
public PartialViewResult ShowOptions()
{
return PartialView();
}
}
下面是它生成的HTML:
Here's the HTML it generates:
<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#admin-options" href="/Admin/Post/ShowOptions">Show Admin Options</a>
看起来好像没什么问题。
Looks fine to me.
而不是做一个AJAX调用,它做了普通的HTTP GET通过浏览器的URL,并重定向到 /管理/后/ ShowOptions
But instead of doing an AJAX call, it does a regular HTTP GET via the browser URL, and redirects to /Admin/Post/ShowOptions.
显然,即时通讯失去了一些东西 - 但什么
Obviously im missing something - but what?
推荐答案
请确保您有unobstrusive AJAX的JavaScript包含在您的网页库。
Make sure you have the unobstrusive AJAX javascript library included in your page.
<script src="<%=Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")%>" type="text/javascript"></script>
这篇关于ASP.NET MVC 3(剃刀)Ajax.ActionLink - 我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!