📜  来自 js 的 mvc asp.net 部分视图 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:24.841000             🧑  作者: Mango

代码示例1
//You can call a Partial View through AJAX

$.ajax({ type: "Get", url: '/GetView', data: mydata, contentType: "application/text; charset=utf-8", dataType: "text", success: function (data, status) { //Use append to add it to the div and not overwrite it //if you have other data in your container $('#containerId').append(data); }, error: function (err) { console.log(err); } }); //In C# /// /// Renders a single view. /// NOTE : PARTIAL VIEW CANNOT RENDER MULTIPLE VIEWS! /// Instead loop through them. /// /// JSON object containing input data /// [HttpGet] public ActionResult GetView(string obj) { //Parse the object into a model try { MyModel model = (new JavaScriptSerializer()).Deserialize(obj); return View("", obj); } catch (Exception ex) { return Json(ex.Message, JsonRequestBehavior.AllowGet); } }