【发布时间】:2023-02-06 14:20:03
【问题描述】:
将表单提交给代码后,我在控制器中得到空值
<form action="Home/Book" method="Post">
<input type="text" id="Name" placeholder="Name">
<input id="Email" type="text" placeholder="Email">
<input id="Number"type="number" placeholder="Mobile Number">
<textarea id="Comment" placeholder="comment here"></textarea>
<button type="submit">Submit</button>
</form>
这是我的控制器代码
public IActionResult Book(Book obj)
{
string name =obj.Name;
name = name + "testing if value is there";
return View();
}
【问题讨论】:
-
您的字段有 ID 但缺少名称。 Difference between id and name attributes in HTML。
标签: .net forms model-view-controller razor