JSON不在MVC中执行编辑操作

时间:2016-10-27 04:17:13

标签: jquery sql-server json asp.net-mvc

[HttpGet]
    [LogInFilter]
    public PartialViewResult MemberEdit(Int32 MemID)  // Update PartialView  
    {
        MemberTbl Mem = db.MemberTbls.Where(x => x.ID == MemID).FirstOrDefault();
        MemberTbl MemInfo = new MemberTbl();

        MemInfo.ID = Mem.ID;
        MemInfo.Name = Mem.Name;
        MemInfo.Post = Mem.Post;
        MemInfo.Phone = Mem.Phone;

        return PartialView(MemInfo);
    }

    [HttpPost]
    [LogInFilter]
    public JsonResult MemberEdit(GarhwalBhawan.Models.MemberTbl MemID)  // Record Update 
    {

        MemberTbl MemDt = db.MemberTbls.Where(x => x.ID == MemID.ID).FirstOrDefault();

        if (ModelState.IsValid)
        {
            MemDt.Name = MemID.Name;
            MemDt.Post = MemID.Post;
            MemDt.Phone = MemID.Phone;
            db.SaveChanges();
            myMessage = "Success";
        }

        else
        {
            myMessage = "Failed";
        }
        return Json(myMessage, JsonRequestBehavior.AllowGet);
    }

我在我的控制器中的上述ActionResult。现在我想借助ID在JSON中保存字段。 我点击该按钮后创建了以下JQuery方法。



  $(document).ready(function () {
        $('#memberSave').click(function () {
            var Name = $("#Name").val();
            var Post = $("#Post").val();
            var Phone = $("#Phone").val();

            var Member = {
               "Name": Name, "Post": Post,
                "Phone": Phone
            };
            $.post("/Admin/MemberEdit", Member,
            function (data) {
                if (data == "Success") {
                    window.location.href = 'MemberView';
                }
                else if (data == "Failed") {
                    alert('Cannot Save!! Please Fill all Details or Contact Support')
                }

                else {
                    alert(data);
                }
            }, 'json');

        });
    });

Thus I've created a button:-
 <input id="memberSave" type="button" value="Save Changes" />
&#13;
&#13;
&#13;

但点击此按钮显示错误: - 无法加载资源:服务器响应状态为500(内部服务器错误) 并告诉我警报: -   提醒(&#39;无法保存!!请填写所有详细信息或联系支持人员&#39;)。

请帮助。

1 个答案:

答案 0 :(得分:0)

您没有将参数“ID”放入参数“Member”