百思不得其解,最终发现,少引用了个jquery插件jquery.unobtrusive-ajax.min.js
表单
@using (Ajax.BeginForm("Send_Comm","Home",new AjaxOptions { HttpMethod = "post",OnSuccess = "back" })) { @Html.TextAreaFor(s => s.comment_txt,new { @class = "text_input_area",@onkeyup = "maxme()",@id = "comment_text" }) <p class="btn" style=" font-size:16px;"> <span id="tips">您还可以输入140字</span> <button type="submit" style="float:right;font-size:16px;" class="W_btn_a"><span class="btn_30px W_f14"><b></b><em> 发 表 </em></span></button> </p> }
ajax回调方法
function back(data) { if (data.Status == 0) { alert("失败"); return; } if (data.Status == 1) { alert(data.Msg); //top.location = "/Main/Main/Index"; } }
[HttpPost] public ActionResult Send_Comm(Domain.comments comment) { Domain.AjaxBackInfo backJson = new AjaxBackInfo(); if (!ModelState.IsValid) { //提交过来的数据有误 } else { backJson.Status = 1; backJson.Msg = "成功啦!"; } return Json(backJson); }原文链接:https://www.f2er.com/ajax/165019.html