0
Ajax.BeginForm重定向到控制Ajax.BeginForm重定向到控制
我創建使用剃刀一個MVC 4應用程序。以下代碼在我的表單上用於提交數據。
@using (Ajax.BeginForm("Topup", "Card", new AjaxOptions { HttpMethod = "POST", OnBegin = "Submitting_Form", OnComplete = "Submitted_Form", UpdateTargetId = "SendStatus"}, new { id="FormSubmit"}))
{
@Html.ValidationSummary()
<ul data-role="listview" data-inset="true">
<li data-role="list-divider">Mobile Topup</li>
<li data-role="fieldcontain">
@Html.LabelFor(m => m.MobileNo)
@Html.TextBoxFor(m => m.MobileNo)
</li>
<li data-role="fieldcontain">
<label class="ui-input-text" id="SendStatus">Test</label>
</li>
<li data-role="fieldcontain">
<input type="submit" value="Topup" />
<input type="button" value="Reset" onclick="this.form.reset(); $('#TopupDate').val(Current_Date('d-m-y'));" />
</li>
<!--<li data-role="list-divider">Navigation</li>-->
<li>@Html.ActionLink("Home", "Index", "Home")</li>
</ul>
}
在控制器
//[AllowAnonymous]
[HttpPost]
public ActionResult Topup(TopupModel model)
{
try {
}
catch (Exception ExC) {
Bug.Bug BG = new Bug.Bug();
BG.Send_Bug_Message(ExC);
}
//return PartialView("PartialTopup", model);
return Content("Success");
}
但經過呈交中,頁面會自動重定向到控制器(例如,http://localhost:43289/Card/Topup
用字符串「未定義」
爲什麼會這樣?我已經列入以下庫
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="/Scripts/MicrosoftAjax.debug.js"></script>
<script src="/Scripts/MicrosoftMvcAjax.debug.js"></script>
檢查後與Firebug,我有一些線索。
POST http://localhost:43289/Card/Topup?Length=4 200 OK 114ms jquery-2.0.3.js (line 7845)
POST http://localhost:43289/Card/Topup?Length=4 200 OK 113ms jquery-2.0.3.js (line 7845)
它發生了兩次。爲什麼? 請幫我解決這個問題。