[英]How to implement a client registration form providing additional dynamically-generated fields using jQuery and Asp.Net MVC 3?
I want to create a registration form for a sport competition using Asp.net MVC 3 (Razor view engine). 我想使用Asp.net MVC 3(Razor视图引擎)为体育比赛创建注册表。
Each school can have only one team consisting of at most 20 members plus 1 team leader. 每所学校只能拥有一个由最多20名成员和1名团队领导组成的团队。
The team leader has to register the members by filling in the registration form I provide. 团队负责人必须通过填写我提供的注册表来注册会员。
Rather than displaying 20 sets of member fields, it is a good idea if I can provide a button Add One More Member
to render an additional set of member fields. 如果我可以提供一个按钮Add One More Member
来呈现另一组成员字段,而不是显示20组成员字段。 This mechanism behaves like Add file
when you want to attach one more file in Yahoo mail. 当您想在Yahoo邮件中附加一个Add file
时,此机制的行为类似于Add file
。
Shortly speaking, I have no idea: 简而言之,我不知道:
Each member has 4 fields: 每个成员有4个字段:
use a form collection in your controller if you don't know the names: 如果您不知道名称,请在控制器中使用表单集合:
public ActionResult(FormCollection formFields)
{
return View();
}
or if you have something like a bunch of team member input textboxes you could give them all the same name and then have an array or list as the parameter: 或者,如果你有一堆团队成员输入文本框,你可以给他们所有相同的名称,然后有一个数组或列表作为参数:
public ActionResult(String[] teamMembers)
{
return View();
}
Further still you can do this with objects: 您还可以使用对象执行此操作:
<input type="textbox" name="TeamMember[0].FirstName" />
<input type="textbox" name="TeamMember[0].LastName" />
<input type="textbox" name="TeamMember[1].FirstName" />
<input type="textbox" name="TeamMember[1].LastName" />
and then in your controller 然后在你的控制器中
public ActionResult(List<TeamMember> teamMemberList)
{
return View();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.