Abhilash J A

Abhilash J A

  • 533
  • 2.4k
  • 598.2k

How to pass model data from dynamic bind cshtml mvc4

Jan 21 2017 4:29 AM
Hello everyone,
 
I have bind list of model data. After I want pass to controller. But the controller model object showing null value. How can I solve this?
 
  1. @model IEnumerable<Reboxwebapp.Models.ViewModel.ProductItemsVM>
  1. @foreach (var item in Model)  
  2.        {  
  3.                if (item.AttributeControlType == "textbox")  
  4.                {  
  5.                    <tr><td>@Html.TextBox("AttributeName", item.AttributeName ?? " ")</td><td>@Html.TextBox("txtValidValues", item.ValidValues ?? " ", new { maxlength = item.AttributeMaxLength ?? 0 })</td></tr>  
  6.                }  
  7.                else if (item.AttributeControlType == "DropDownList")  
  8.                {  
  9.                    <tr><td>@Html.TextBox("AttributeName", item.AttributeName ?? " ")</td><td>@Html.DropDownList("ddlValidValues", new SelectList(item.ValidValues.Split(new char[] { ',' })), new { style = "height: 20px;"size = item.AttributeMaxLength ?? 0 })</td></tr>  
  10.                }  
  11.                else if (item.AttributeControlType == "checkbox")  
  12.                {  
  13.                    <tr><td>@Html.TextBox("AttributeName", item.AttributeName ?? " ")</td><td><ul><li> <input type="checkbox" id="chkValidValue" checked /></li>@item.ValidValues<li></ul></td></tr>  
  14.                }            
  15.        } 

Answers (3)