【发布时间】:2017-09-05 12:18:28
【问题描述】:
我正在尝试让我的 .net 核心 MVC 网站接收我通过 javascript 从视图发送的 JSON。可悲的是,模型似乎没有被数据填充。
[HttpPost]
public ActionResult AddSubtitles(AddSubtitleSettingsModel model)
{
/* do things and save to database */
return RedirectToAction("Subtitling");
}
我的模特:
public class AddSubtitleSettingsModel
{
public HashSet<string> from { get; set; }
public HashSet<string> to { get; set; }
public decimal startupRateLessThanOneMinute { get; set; }
public decimal startupRateBetweenOneAndThreeMinutes { get; set; }
public decimal pricePerSubtitle { get; set; }
public decimal defaultRateTranslators { get; set; }
}
我可以告诉模型没有被填充,因为我在动作中放置了一个断点并检查了模型,并且一切都是空/空的:
这就是我从 javascript 发送请求的方式:
let fromValues: any = fromLanguages.getValue();
let toValues: any = toLanguages.getValue();
var data = {
from: fromValues.map((l: any) => l.value),
to: toValues.map((l: any) => l.value),
startupRateLessThanOneMinute: Number($('#srLt1m').val()),
startupRateBetweenOneAndThreeMinutes: Number($('#stBt13m').val()),
startupRateBetweenThreeAndFiveMinutes: Number($('#stBt35m').val()),
pricePerSubtitle: Number($('#pPS').val()),
defaultRateTranslators: Number($('#dRT').val())
}
fetch('/Settings/AddSubtitles', {
method: 'post',
body: JSON.stringify(data)
}).then((response: any) => {
console.log(response);
});
任何建议将不胜感激。
【问题讨论】:
标签: c# asp.net-core-mvc