简体   繁体   English

如何实现客户端注册表单,使用jQuery和Asp.Net MVC 3提供额外的动态生成字段?

[英]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: 简而言之,我不知道:

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

Edit 编辑

Each member has 4 fields: 每个成员有4个字段:

  1. FirstName (string) FirstName(字符串)
  2. LastName (string) LastName(字符串)
  3. BirthDate (datetime) BirthDate(datetime)
  4. Photograph (image file) 照片(图像文件)

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.

相关问题 如何使用 jquery unobtrusive 和 Asp.Net Mvc 验证动态生成的单选按钮组? - How to validate dynamically generated radio button group using jquery unobtrusive and Asp.Net Mvc? 删除,替换或禁用动态生成的ASP.Net js代码 - Remove, replace or disable dynamically-generated ASP.Net js code 如何将带有文件的注册表发布到 ASP.NET MVC 操作 - How to Post Registration Form with File to ASP.NET MVC Action 如何在asp.net中使用C#将使用jquery flot动态生成的图表导出到Excel中? - How to export charts which are dynamically generated by using jquery flot into Excel using C# in asp.net? 如何使用jQuery将事件处理程序附加到动态生成的DOM元素上? - How can I attach event handlers to dynamically-generated DOM elements using jQuery? 如何通过jQuery访问动态生成的页面内容? - How to access dynamically-generated page content via jQuery? 在ASP.NET MVC中使用jQuery动态删除表行 - delete table row dynamically using jQuery in asp.net mvc 使用JQuery动态加载ASP.NET MVC部分视图 - Load ASP.NET MVC Partial Views Dynamically Using JQuery 问题 <form> 和动态生成的链接 - Problems with <form> and Dynamically-generated links 如何通过使用客户端中的jQuery筛选asp.net mvc中的HTML表列表 - How to Filter the Html Table list in asp.net mvc by using jquery in client side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM