首页 > 解决方案 > 是否可以使用 Jquery Ajax 调用控制器并在视图中加载模型(而不是在部分视图中)

问题描述

我现在有一个使用 ajax 调用控制器的代码,它工作正常。当我即将在视图中加载模型时,我现在的问题。我有一个 jquery 错误。还要注意我重用视图来加载模型

阿贾克斯代码

$.ajax({
                    type: 'POST',
                    url: '@Url.Action("GetEmployeeDetails", "Employee")',
                    contentType: "application/json; charset=utf-8",
                    dataType: 'json',
                    cache: false,
                    success: function (data) {
                        //how to load the data in the index view?
                    },
                    error: function () {
                        alert("Connection Failed. Please Try Again.");
                    }
                });

在员工控制器中

[HttpPost]
public ActionResult GetEmployeeDetails()
{

    var model = new EmployeeDetails();//  I got the logic inside of this

   //reused the existing view
   return View("Index", model);
}

我对其进行了调试,并确认我可以通过直到将模型返回给 View 然后我将在 AJAX 中出现错误

标签: jqueryajaxasp.net-mvcmodel-view-controller

解决方案


推荐阅读