【发布时间】:2012-01-10 14:39:29
【问题描述】:
我对 MVC3 中的 AjaxOption 感到困惑,我想发出 post 请求,但它总是发出 get 请求并重定向到新的 url。
我的 .cshtml 代码如下
<div >
@Html.ActionLink("Check Availability", "ValidateUsername", "Wizard", new { username = "arun"},
new AjaxOptions()
{
Url="/Wizard/ValidateUserName",
UpdateTargetId = "msg",
HttpMethod = "POST",
LoadingElementId = "progress"
})
</div>
<div id="progress">
<img alt="" src="../../Content/Images/progress.gif" width="20px" height="20px" style="display: none" />
</div>
<div id="msg">
</div>
和控制器操作如下
public ActionResult ValidateUsername(string username)
{
Thread.Sleep(200);
//return Json(!username.ToLower().Equals("arun"));
return Json(true , JsonRequestBehavior.AllowGet);
}
总是发出 get 请求而不是 POST 请求并重定向到新 URL http://localhost:55152/Wizard/ValidateUsername?username=arun,为什么?
和下面生成的HTML代码
<div >
<a Confirm="" HttpMethod="POST" InsertionMode="Replace" LoadingElementDuration="0" LoadingElementId="progress" OnBegin="" OnComplete="" OnFailure="" OnSuccess="" UpdateTargetId="msg" Url="/Wizard/ValidateUserName" href="/Wizard/ValidateUsername?username=arun">Check Availability</a>
</div>
<div id="progress">
<img alt="" src="../../Content/Images/progress.gif" width="20px" height="20px" style="display: none" />
</div>
<div id="msg">
</div>
【问题讨论】:
标签: asp.net-mvc-3 razor