動的フォーム フィールドは、次のように簡単に実現できます。
モデル:
public class MyViewModel
{
public string Name { get; set; }
public List<string> EmailAddresses { get; set; }
}
意見:
@model MyViewModel
@Html.TextboxFor(m => m.Name)
@* you can add as many of these as you like, or add them via javascript *@
<input type="text" name="EmailAddresses" />
<input type="text" name="EmailAddresses" />
<input type="text" name="EmailAddresses" />
@* you can also use razor syntax *@
@Html.Textbox("EmailAddresses")
コントローラ:
[HttpPost]
public ActionResult MyAction(MyViewModel model)
{
// note that model.EmailAddresses contains your list of email addresses
foreach (string email in model.EmailAddresses)
email = email; // do whatever you want with this...
return View();
}