遇到鬼了,Ajax.BeginForm提交表单,页面居然会跳转?? !!!!

前端之家收集整理的这篇文章主要介绍了遇到鬼了,Ajax.BeginForm提交表单,页面居然会跳转?? !!!!前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


百思不得其解,最终发现,少引用了个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

猜你在找的Ajax相关文章