你的位置:首页 > ASP.net教程

[ASP.net教程]MVC Action返回Json


Action
[HttpPost]
        public ActionResult Edit(Study_CourseHourModel model)
        {
            if (ModelState.IsValid)
            {
                model.UId = LoginUserId;
                bool flag = BLLControl.Study_CourseHourBLL.Update(model);
                if (flag)
                {
                    return this.Json(new { Result = 1, Msg = "操作成功"  }, JsonRequestBehavior.AllowGet);
                }
                return Json(new { Result = 2, Msg = "操作失败" }, JsonRequestBehavior.AllowGet);
            }
            return ActionResult_ModelErrors();

        }

 
Js:
   $("#editCH").click(function () {
        $("form").ajax({
            type: "POST",
            dataType: "json",            url: "/Member/CourseHour/Edit",
            success: function (data) {
                showTips("操作成功");
                window.location.href = "/Member/CourseHour/Index?courseId=" + $('#Study_Course').val();
            }
        });
    });