是否可以使用Jquery Ajax调用控制器并在View中加载模型(不在部分视图中)

时间:2018-04-26 13:44:07

标签: jquery ajax asp.net-mvc model-view-controller

我现在有一个代码,使用ajax调用控制器,它运行正常。我现在的问题是当我要在视图中加载模型时。我有一个jquery错误。另请注意,我重复使用视图来加载模型

Ajax代码

$.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中出错

0 个答案:

没有答案
相关问题