返回带有通过jQuery AJAX指定的路径的MVC 5视图不起作用

问题描述 投票:0回答:1

我使用jQuery AJAX调用MVC5 ActionResult来返回一个View。 ActionResult返回与它结合的视图(据推测),但显示的是布局页面,而不是我想要的视图。

我在这个网站上尝试了很多答案,包括视图的相对URL或其他一些视图,但没有成功

public ActionResult GetSomePartialView(string personId)
{
  IdentityUserViewModel identityUserViewModel = new IdentityUserViewModel();
  ExBool iUser = personBo.GetById(int.Parse(personId), out Person model);
  return View(model);
  //return View("~/Views/Person/EditPerson.cshtml",model);
}
$.ajax({
  type: "POST",
  url: "/Person/GetSomePartialView/",
  data: jsonModelData,
  contentType: "application/json; charset=utf-8",
  dataType: "html",
  success: function (jsReturnArgs) {
    $("#tabDetails").html(jsReturnArgs); // the HTML I returned from the controller
  },
  error: function (errorData) {
    alert("error: " + errorData);
  }
});
jquery ajax view asp.net-mvc-5
1个回答
1
投票

您应该使用PartialView方法而不是View方法。

return PartialView(viewName, model);

并更改sign方法以返回部分视图结果

 public PartialViewResult GetSomePartialView(string personId)
 {
     IdentityUserViewModel identityUserViewModel = new IdentityUserViewModel();
      ExBool iUser = personBo.GetById(int.Parse(personId), out Person model);
      return PartialView("viewName",model);
 }
© www.soinside.com 2019 - 2024. All rights reserved.