[英]Unable to call API Post Method that has a class parameter with [FromBody] attribute in asp.net core mvc
[英]ASP.NET MVC Core - Post form to class parameter
<form method="post" id="modalForm" action="/Test/TestForm" target="myframe">
<input type="text" name="id" required />
<input type="text" name="name" required />
<input type="submit" value="Post" onsubmit="alert('after post!');" />
</form>
[HttpPost]
public IActionResult TestForm(Test test)
{
return View();
}
public class Test
{
public string id;
public string name;
}
需要在表單上進行哪些更改以獲取測試 class 的值? 當前值為 null? 我想保持簡單,沒有 ASP.NET 核心助手。
C# 提供了一種使用速記/自動屬性的方法,您只需編寫get;
並set;
物業內。
public class Test
{
public string id { get; set; }
public string name { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.