百思不得其解,最终发现,少引用了个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" })
您还可以输入140字
发 表
}
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);
}
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
小编个人微信号 jb51ccc
喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!