简体   繁体   中英

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,

<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. 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# ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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