我试图将带有表单数据的数组发送到带有Ajax请求的操作,但每当我这样做时,我都会收到表单数据和数组为空
$scope.SubmitForm = function () {
var sLangs = $("#supportedLanguages").data("kendoMultiSelect").value();
var formdata = new FormData($('#frmAppSettings').get(0));
alert(formdata.SelectedLanguages);
var data = new FormData(document.getElementById("frmAppSettings"));
$.ajax({
type: "POST",
url: "/AppMenuMaker/AppSettings",
data: JSON.stringify({ AppSettingsView: formdata, SelectedLangs: sLangs }),
processData: false,
contentType: false,
success: function () {
}
});
}`
Run Code Online (Sandbox Code Playgroud)
我的行动如下
[HttpPost]
[Authorize]
public ActionResult AppSettings( ApplicationSettingsViewModel AppSettingsView, int[] SelectedLangs)
{
}
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
我正在使用 angular 6 尝试使用 httpclient 发送 post 请求,但总是在服务器端收到空正文。
save( rules:RuleModel[]){
let _headers: HttpHeaders = new HttpHeaders({
'Content-Type': 'application/json; charset=utf-8'
});
return this._httpClient.post(AppConfig.BaseUrl,JSON.stringify(rules), {headers:_headers} ); }
Run Code Online (Sandbox Code Playgroud)
和 API 函数
[HttpPost]
public List<Rule> AddTemplateTextRules( [FromBody]Rule[] Rules)
{
try
{
return RuleManager.AddRule(Rules);
}
catch (Exception e)
{
return null;
}
return null;
}
Run Code Online (Sandbox Code Playgroud)