我有一個模型:
public class CompanyFooterUpdateModel
{
public CompanyFooterUpdateModel(){}
public Guid CompanyId { get; set; }
public string FooterHtml { get; set; }
}
控制器:
public async Task<IActionResult> SaveFooter([FromBody] CompanyFooterUpdateModel model)
{
//.... do something in Company controller
}
查看,使用 axios 帖子:
function SaveCompanyFooter() {
axios.post('@Url.Action("SaveFooter", "Company")',
{
model: {
FooterHtml: window.HtmlEditor.getData(),
CompanyId: "@Model.CompanyId"
}
}
).then(response => {
// .... do something
});
}
然后,我嘗試了一切,[FromBody],任何其他,什么都沒有……請解釋一下,我做錯了什么?
UPD1: 所以我也嘗試過這樣的事情:
axios.post('@Url.Action("SaveFooter", "Company")',
{
"FooterHtml": window.HtmlEditor.getData(),
"CompanyId": "@Model.CompanyId"
}
)
和
public async Task<IActionResult> SaveFooter(Guid CompanyId, string FooterHtml)...
UPD2: 控制器動作截圖
JS 視圖
uj5u.com熱心網友回復:
嘗試從 javascript 中洗掉 "
axios.post('@Url.Action("SaveFooter", "Company")',
{
FooterHtml: window.HtmlEditor.getData(),
CompanyId: "@Model.CompanyId"
}
)
或嘗試添加 json 標頭
axios.post('@Url.Action("SaveFooter", "Company")',
{
FooterHtml: window.HtmlEditor.getData(),
CompanyId: "@Model.CompanyId"
}
),
{
'Content-Type': 'application/json'
})
.then((response) => {
.....
并使用此操作
public async Task<IActionResult> SaveFooter([FromBody] CompanyFooterUpdateModel model)
{
//.... do something in Company controller
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/329439.html
標籤:C# 邮政 公理 asp.net-core-mvc
