简体   繁体   English

将具有动态元素名称的表单绑定到MVC C#中的模型类

[英]Binding form with dynamic element names to a model class in MVC c#

I was trying to bind the post-data of this form to a MVC model class, 我试图将此表单的后数据绑定到MVC模型类,

<form>
  <div criteriaid=”59”>
    <input type="hidden" value="FRON 01" name="criteriaProduct[59]">
    <input type="hidden" value="FRON 02" name="criteriaProduct[59]">  
    <input type="hidden" value="FRON 04" name="criteriaProduct[59]">
  <div>

  <div criteriaid=”60”>
    <input type="hidden" value="FRON 02" name="criteriaProduct[60]">
    <input type="hidden" value="FRON 01" name="criteriaProduct[60]">  
    <input type="hidden" value="FRON 04" name="criteriaProduct[60]">
  <div>

  <div criteriaid=”61”>
    <input type="hidden" value="FRON 05" name="criteriaProduct[61]">
    <input type="hidden" value="FRON 06" name="criteriaProduct[61]">  
    <input type="hidden" value="FRON 01" name="criteriaProduct[61]">
  <div>
</form>

The problem is the criteria id is dynamic and the products has to be grouped by criteria Id. 问题在于条件ID是动态的,并且必须按条件ID对产品进行分组。 I tried 我试过了

Class
{
    public string[][] criteriaProduct { get; set; }  // not working
    public string[] criteriaProduct { get; set; } // not working
}

Any one can help? 有人可以帮忙吗? Thanks I know this array name is ok in PHP, but c# ? 谢谢,我知道此数组名称在PHP中可以,但是c#吗?

有关数组绑定的完整信息,请参见Hancelman博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM