【发布时间】:2018-03-17 19:28:42
【问题描述】:
下面我正在尝试在 CustomerModel Razor 页面中对操作方法/处理程序进行发布请求。
RazorPage 名称为“Customer.cshtml”
从 Ajax 请求绑定 DropdownList
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
<select class="form-control" id="CustomerID"
name="CustomerID"
asp-for="Customer.CustomerID"
asp-items="@(new SelectList(string.Empty,"CustomerID", "Name"))">
</select>
Ajax 请求
我也尝试只调用处理程序,但它显示错误
<script type="text/javascript">
$(document).ready(function ()
{
$.ajax({
type: 'GET',
// we are calling json method
// /Pagename/ActionMethod
// /Pagename/Handler(OnGetListofCustomer)
url: '/Customer/OnGetListofCustomer',
contentType: "application/json",
success: function (data) {
$("#CustomerID").append('<option value="' + "0" + '">' + "Select State" + '</option>');
debugger;
$.each(data, function (i, state) {
$("#CustomerID").append('<option value="' + state.CustomerID + '">' + state.Name + '</option>');
});
},
error: function (ex) {
alert('Failed to retrieve states.' + ex);
}
});
});
页面模型
发出 Ajax 请求时出错
【问题讨论】:
-
还记得设置 AntiForgery Token 参见:stackoverflow.com/questions/46410716/…
标签: asp.net-mvc asp.net-core asp.net-core-2.0 razor-pages