【发布时间】:2014-06-13 10:52:41
【问题描述】:
我正在使用 .NET MVC4
我用过的javascript函数如下:
function ShowDomainComponentDetail(compCode) {
alert(compCode);
$.ajax({
url: "/PP/getDomainComponentDetailWithDomain",
data: {
'ComponentCode': compCode
},
dataType: "json",
type: 'POST',
cache: false,
success: function (_responseData) {
$('#divShowDomainCompDetail').show();
alert(_responseData.Data)
},
error: function () {
//
}
});
}
成功后,我将在 .net 中获得以下列表:
IdObservation=1, ObservationName="Started" , ObsType="Announced";
IdObservation=2, ObservationName="Not Started" , ObsType="Un Announced";
IdObservation=3, ObservationName="Declared" , ObsType="Announced";
我的问题是我无法在 Ajax 成功块中访问此列表。
我如何访问此列表:
alert(_responseData.IdObservation);
alert(_responseData.ObservationName);
(接下来我将把它分配给标签)。
请帮帮我。
编辑 1:
我的服务器端函数返回列表:
public JsonResult getDomainComponentDetailWithDomain(string ComponentCode)
{
try
{
List<TEAMS_PP.Entity.correlations> compDetail_list = new correlation().getDomainComponentDetailswithDomain(ComponentCode);
return Json(compDetail_list);
}
catch (Exception)
{
List<TEAMS_PP.Entity.correlations> BlankList = new List<TEAMS_PP.Entity.correlations>();
return Json(BlankList);
}
}
【问题讨论】:
-
如何从服务器返回列表?
-
@James 请看 EDIT1
-
Cool 只是确保您正确地发回它,您的结果是一个简单的对象数组(如果您使用调试器,您可以看到)。请参阅下面@Bhushan 的回答。
-
@James 是的,答案有效!!!感谢您与我的问题分享时间:)
标签: c# javascript jquery .net json