【发布时间】:2020-01-14 13:19:02
【问题描述】:
我的Kcnockout Js有问题,当他尝试返回结果时,他将结果返回给我,我已经验证了承包商,如果他正在向我返回数据,如下图所示,
但是当在视图中加载值列表时,它让我认为它是未定义的,如下图所示,
我不知道他为什么给我发这条消息,这是我的控制器代码,
public JsonResult GetGender()
{
ServiceResult serviceResult = new ServiceResult();
serviceResult = this._genderServices.GetListGenders();
return Json(serviceResult);
}
这是查看代码,
<h2>Generos</h2>
<hr />
<p data-bind="visible: IsNewButton">
<a href="#" data-bind="click: New" class="btn btn-primary">Crear Nuevo</a>
</p>
<div id="divListGenders" data-bind="visible: ShowResult">
<table class="table">
<thead>
<tr>
<th>
Genero
</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody data-bind="foreach: Genders">
<tr>
<td style="text-align:left" data-bind="text: GenderName"></td>
<td style="text-align:center">
<a href="#" data-bind="click: $parent.Edit" class=" btn btn-warning"><span class="glyphicon glyphicon-edit"></span></a> |
<a href="#" data-bind="click: $parent.Details" class=" btn btn-info"><span class="glyphicon glyphicon-eye-open"></span></a> |
<a href="#" data-bind="click: $parent.Delete" class=" btn btn-danger"><i class="fas fa-trash"></i></a>
</td>
</tr>
</tbody>
</table>
</div>
<div data-bind="visible: IsBackToListButton">
<a href="#" data-bind="click: BackToList" class="btn btn-info">Regresar</a>
</div>
<script src="~/js/Gender.js"></script>
这是返回流派列表的方法,
var LoadListGenders = function () {
$.ajax({
url: '/AdminGenders/GetGender',
data: null,
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
async: true,
success: function (data) {
if (data.Success) {
genderViewModel.Genders.removeAll();
genderViewModel.Genders(data.Data);
}
else {
alert(data.Data);
}
},
error: function (ex) {
alert('Ocurrión un error, cargando los generos.');
}
});
};
}
我在 asp.net MVC 5 上提供了它,它运行良好,我不知道为什么它在 ASP.NET Core 2.1 中对我不起作用,不胜感激
【问题讨论】:
标签: javascript jquery ajax asp.net-core knockout.js