[英]C# - How do I pass a model with another model inside from a HTML form in ASP.NET MVC
I have this form I'm trying to pass to my controller. 我正在尝试将此表格传递给我的控制器。 I have another model inside the main model. 我在主模型中有另一个模型。
he models and the form are like this. 他的模特和形式是这样的。 Don't know if the controller will pickup the model like this 不知道控制器是否会像这样拾取模型
public class Entry{
public string id { get; set;}
public string department { get; set; }
public Supervisor supervisor { get; set; }
}
public class Supervisor{
public string name { get; set; }
public string employeeID { get; set; }
}
<form action="Home/Upload" method="post" style="border:solid #000 1px; padding:5px">
<fieldset>
<legend>Entry</legend>
ID: <input type="text" name="id" />
Department: <input type="text" name="department" />
<br /><br />
Supervisor<br />
Name: <input type="text" name="name"/>
Employee Id: <input type="text" name="employeeID"/><br />
<input type="submit" value="Submit"/>
</fieldset>
</form>
public class HomeController : Controller {
[HttpPost]
public ActionResult Upload(Entry newEntry){
Database db = new Database();
bool result = db.add(newEntry);
return View("UploadResult", result);
}
}
For the supervisor details you have to name it accordingly as : 对于主管的详细信息,您必须相应地将其命名为:
Name: <input type="text" name="supervisor.name"/>
Employee Id: <input type="text" name="supervisor.employeeID"/><br />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.