Asp.net mvc 如何将动态视图绑定到控制器?
如何将字段绑定到用户控制器(asp.net mvc)Asp.net mvc 如何将动态视图绑定到控制器?,asp.net-mvc,asp.net-core,Asp.net Mvc,Asp.net Core,如何将字段绑定到用户控制器(asp.net mvc) 谢谢你的帮助 如何将字段绑定到用户控制器 要实现该要求,可以参考以下示例代码 用户类 测试结果 如何将字段绑定到用户控制器 要实现该要求,可以参考以下示例代码 用户类 测试结果 <form method="post" action="/Forms/Users"> <input asp-for="FirstName" class="form-control" /> <input asp-for="La
谢谢你的帮助
如何将字段绑定到用户控制器
要实现该要求,可以参考以下示例代码
用户类
测试结果
如何将字段绑定到用户控制器
要实现该要求,可以参考以下示例代码
用户类
测试结果
<form method="post" action="/Forms/Users">
<input asp-for="FirstName" class="form-control" />
<input asp-for="LastName" class="form-control" />
<% for(int i = 0; i < n; i++){ %>
<input type="text" name="Field[<%= i %>]" />
<% } %>
</form>
public class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
public List<string> Field { get; set; }
}
public IActionResult Index()
{
var model = new User
{
Field = new List<string> { "Age" ,"Email" }
};
return View(model);
}
@model User
<form method="post" action="/Forms/Users">
<input asp-for="FirstName" class="form-control" />
<input asp-for="LastName" class="form-control" />
@foreach (var field in Model.Field)
{
<input type="text" name="Field" class="form-control" />
}
<input type="submit" value="Submit" />
</form>
public IActionResult Users(User model)
{
//code logic here
return View();
}