MVC json方法使用
js部分:
$.ajax({ type: "POST", url: "/Auth/GetVedioInfo", data: { "menuid": id }, success: function(request) { $("#loginip").val(request.message.IpAddressInfor); $("#port").val(request.message.Port); $("#username").val(request.message.UserName); $("#password").val(request.message.PassWords); alert($("#loginip").val()); clickLogin(); } });
控制器部分: /// </summary> /// <param name="ids">监控信息</param> /// <returns></returns> [HttpPost] public ActionResult GetVedioInfo(int menuid) { var model = this.TestService.GetTest(menuid); var res = new JsonResult(); var person = new { message = model }; res.Data = person;//返回单个对象; res.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return res; }