【发布时间】:2014-12-11 09:05:22
【问题描述】:
我的代码似乎有一点错误。但是我找不到。
所以,我正在通过我的 ajax 函数在我的控制器中调用一个动作。
var serviceURL = '/Vm/GetVMInformation';
$.ajax({
type: "GET",
url: serviceURL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert("This Works fine");
$("#testDiv").html(result); // Display the partial View in this div
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
My Action 然后返回一个局部视图和一个列表对象。
public ActionResult GetVMInformation()
{
List<VmInfo> VMListArray = new List<VmInfo>();
... Code ...
return PartialView("_List", VmList);
}
Action 被调用,部分 View 工作。我测试了它。 所以问题是,我的 ajax 函数没有成功。所以它会抛出一个错误。当我警告错误时,我只会收到“内部服务器错误”。
有人看到我的错误吗?
注意: 我的片面看法。不确定它是否重要
<!--This partial View is just for testing the ajax function-->
@model IsolutionsAzureManager.Models.VmData
<p>@Model.Name[0]</p>
更新:
所以我将函数的返回类型(现在是 JsonResult 类型)更改为 Json
JavaScriptSerializer jss = new JavaScriptSerializer();
string output = jss.Serialize(VmList);
Response.Write(output);
Response.Flush();
Response.End();
return Json("_List", output);
好消息:ajax 调用现在成功了。 坏消息:我仍然无法显示我的部分视图。返回值(结果)就是 [object, Object]
success: function (result) {
$("#testDiv").html(result);
},
【问题讨论】:
标签: jquery asp.net-mvc razor