Abhilash J A

Abhilash J A

  • 531
  • 2.4k
  • 600.9k

Need advice for update a table in MVC.

Apr 19 2017 6:08 AM
Hi,
 
I have 'Product Category Attribute' table,
 
 
Then, I want to create dynamically generating html controls with respect to this table. So I have designed html like this,
  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.                    @Html.Hidden("idProductCategoryAttribute", item.idProductCategoryAttribute)  
  7.                }  
  8.                else if (item.AttributeControlType == "DropDownList")  
  9.                {  
  10.                    <tr><td>@Html.TextBox("AttributeName", item.AttributeName ?? " ")td><td>@Html.DropDownList("ddlValidValues", new SelectList(item.ValidValues.Split(new char[] { ',' })), new { @class = "form-control", @style = "width:200px;height:20px;"size = item.AttributeMaxLength ?? 0 })td>tr>  
  11.                    @Html.Hidden("idProductCategoryAttribute", item.idProductCategoryAttribute)  
  12.                }  
  13.                else if (item.AttributeControlType == "checkbox")  
  14.                {  
  15.                    <tr><td>@Html.TextBox("AttributeName", item.AttributeName ?? " ")td><td><ul><li> <input type="checkbox" id="chkValidValue" checked />li>@item.ValidValues<li>ul>td>tr>  
  16.                    @Html.Hidden("idProductCategoryAttribute", item.idProductCategoryAttribute)  
  17.                }  
  18.            } 
Now View,
 
 
 
 
Now If I have to update the 'ValidValues' by one button click, how can I do this?
 
I have tried jquery,
  1. $( "#btnAddProduct" ).click(function() {   
  2. var values = $('input[name="idProductCategoryAttribute"]').map(function () {  
  3.             return this.value;  
  4.         }).get();  
  5.         var hdidAttribute = values.join(", ");  
  6.       /*before submitting the form*/  
  7. }); 
 Here now getting all 'idProductCategoryAttribute', but how can I update the 'ValidValues' with respect to each 'idProductCategoryAttribute' id?

Answers (3)