ASP.NET MVC:检索具有相同名称的表单字段 [英] ASP.NET MVC: Retrieving form fields with the same name

查看:146
本文介绍了ASP.NET MVC:检索具有相同名称的表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有方法来检索具有相同名称的表单域除了使用modelbinders或逗号分割。

Is there are way to retrieve form fields with the same name besides using modelbinders or comma splitting.

我有相同名称的几个文本框,我通过他们需要循环和检索每个值。

I have a few textfields with the same name and i need to loop through them and retrieve each value.

感谢您

推荐答案

的FormCollection是一个NameValueCollection中。这意味着你可以这样做:

FormCollection is a NameValueCollection. That means you can do:

public ActionResult MyAction(FormCollection form)
{
  // ModelBinder will set "form" appropriately
  foreach(var value in form.Getvalues("duplicatedFieldname"))
  {
    //do something with value
  }
}

这篇关于ASP.NET MVC:检索具有相同名称的表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆