如何使用jQuery和Asp实现提供附加动态生成字段的客户端注册表单。净MVC 3 ?

时间:2021-09-09 04:03:28

I want to create a registration form for a sport competition using Asp.net MVC 3 (Razor view engine).

我想用Asp.net MVC 3 (Razor view engine)为体育比赛创建一个注册表单。

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. This mechanism behaves like Add file when you want to attach one more file in Yahoo mail.

与其显示20组成员字段,不如提供一个按钮,增加一个成员,以呈现一组额外的成员字段。当您希望在Yahoo mail中附加一个文件时,此机制的行为类似于添加文件。

Shortly speaking, I have no idea:

简单地说,我不知道:

  1. Is there a mature implementation of jQuery available to implement a form providing additional dynamically-generated form fields?
  2. 是否有成熟的jQuery实现来实现提供额外动态生成的表单字段的表单?
  3. How to implement this scenario in Asp.net MVC 3? How to manage the unknown number of posted form fields?
  4. 如何在Asp.net MVC 3中实现这个场景?如何管理已发布表单字段的未知数量?

Edit

Each member has 4 fields:

每个成员有4个字段:

  1. FirstName (string)
  2. FirstName(字符串)
  3. LastName (string)
  4. 姓(字符串)
  5. BirthDate (datetime)
  6. 生日(datetime)
  7. Photograph (image file)
  8. 照片(图片文件)

1 个解决方案

#1


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();
}

#1


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();
}