MVC 不接受参数作为枚举
MVC doesn't accept parameter as enum
我试图通过 AJAX 调用从 js 传递一个参数到我的 MVC 控制器,但它将它解释为 null。他们有办法解决这个问题吗?
AJAX 来电
service.GetYearsByType = function (docType) {
var response = $http({
method: 'GET',
url: '/Budget/GetYearsByType/' + docType
});
return response;
}
MVC
public ActionResult GetYearsByType(DocType? docType)
{
.....
}
我尝试将 http
调用更改为 POST
,但仍然无效。我将 docType?
更改为 int?
并且 mvc 能够识别它所以问题一定是 enum
变量 DocType
我不这么认为,参数枚举类型是问题的原因。你可以试试这个:
service.GetYearsByType = function (docType) {
$.ajax({
method: 'POST',
dataType: 'json',
url: '/Budget/GetYearsByType/',
contentType: "application/json; charset=utf-8",
data: { 'docType': docType},
success: function (data) {
alert('scuess');
},
error: function (xhr) {
alert(xhr.responseText);
},
});
}
我试图通过 AJAX 调用从 js 传递一个参数到我的 MVC 控制器,但它将它解释为 null。他们有办法解决这个问题吗?
AJAX 来电
service.GetYearsByType = function (docType) {
var response = $http({
method: 'GET',
url: '/Budget/GetYearsByType/' + docType
});
return response;
}
MVC
public ActionResult GetYearsByType(DocType? docType)
{
.....
}
我尝试将 http
调用更改为 POST
,但仍然无效。我将 docType?
更改为 int?
并且 mvc 能够识别它所以问题一定是 enum
变量 DocType
我不这么认为,参数枚举类型是问题的原因。你可以试试这个:
service.GetYearsByType = function (docType) {
$.ajax({
method: 'POST',
dataType: 'json',
url: '/Budget/GetYearsByType/',
contentType: "application/json; charset=utf-8",
data: { 'docType': docType},
success: function (data) {
alert('scuess');
},
error: function (xhr) {
alert(xhr.responseText);
},
});
}