weixin_33712987 2015-07-30 06:57 采纳率: 0%
浏览 27

JSON“返回JSON()”修复MVC 4

  @using (Html.BeginForm(null, null,FormMethod.Post , new {@class="form-horizontal"}))
                                        {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
  <button type="submit" class="btn btn-success">
      <i class="fa fa-save"></i>&nbsp;
         Save
     </button>
}     

 $.ajax({
                type: "POST",
                url: "Home/EditProfile",
                traditional: true,
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify(m),
                dataType: 'json',
                success: function (data) {
                    if(data == "Hello")
                    {
                     alert("Hello");
                    }

                    if (data=="error")
                    {

                }
            },
            error: function (data) { console.log(data) } 
        });


 [HttpPost]
 public ActionResult EditProfile(ModelUserProfile m)
        {

                   return Json("Hello");

        }

Okay what its return is the following page: Fix

That is "Hello" written on the Blank Page?

But it should gimme alert "Hello". What is wrong?? Note: I am using because of @html.BeginForm()

  • 写回答

1条回答 默认 最新

  • 程序go 2015-07-30 07:34
    关注
        @using (Html.BeginForm(null, null, FormMethod.Post, new { @class = "form-horizontal" }))
        {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true)
            <button type="button" id="btnsubmit" class="btn btn-success">
                <i class="fa fa-save"></i>&nbsp;
                Save
            </button>
        }
    
    
    
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>
    <script>
        $(document).ready(function () {
            var m = {};
            m.name = "Ravi"; //What ever the object mention the properties //properly
            $('#btnsubmit').click(function () {
                $.ajax({
                    type: "POST",
                    url: "../Home/EditProfile",
                    traditional: true,
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify(m),
                    dataType: 'json',
                    success: function (data) {
                        if (data == "Hello") {
                            alert("Hello");
                        }
    
                        if (data == "error") {
    
                        }
                    },
                    error: function (data) { console.log(data) }
                });
            });
        });
    
    </script>
    
    
    **Controller**
    
          public ActionResult EditProfile()
            {
                return View();
            }
            [HttpPost]
            public ActionResult EditProfile(ModelUserProfile m)
            {
                return Json("Hello");
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ssh登录页面的问题
  • ¥60 渗透一个指定银行app,拿到客户信息,需要什么级别
  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问
  • ¥15 用MATLAB汇总拟合图