javascript - How to enable jquery to insert multiple row to database which include @Html.DropDownListFor in the table -


i'm new mvc , jquery
when use dropdownlist in table, jquery code never work
table without dropdownlist, code of jquery work perfect
must edit in jquery code work perfect
code

<div><a href="#" id="addnew">add new</a></div> <table id="datatable" border="0" cellpadding="0" cellspacing="0">     <tr>         <th>color</th>         <th>windowtype</th>         <th>height</th>         <th>width</th>         <th></th>     </tr>     @if (model != null && model.count > 0)     {         int j = 0;         foreach (var item in model)         {             <tr style="border:1px solid black">                 <td>@html.dropdownlistfor(m => m[j].color, (selectlist)viewbag.color)</td>                 <td>@html.dropdownlistfor(m => m[j].windowtype, (selectlist)viewbag.windowtype)</td>                 <td>@html.textboxfor(m => m[j].height, new { @class = "form-control" })</td>                 <td>@html.textboxfor(m => m[j].width, new { @class = "form-control" })</td>                 <td>                     @if (j > 0)                     {                         <a href="#" class="remove">remove</a>                     }                 </td>             </tr>                     j++;         }     } </table>     <input type="submit" value="save bulk data" /> 

this in code of jquery

@section scripts{     @scripts.render("~/bundles/jqueryval")     <script language="javascript">         $(document).ready(function () {              //1. add new row             $("#addnew").click(function (e) {                 e.preventdefault();                 var $tablebody = $("#datatable");                 var $trlast = $tablebody.find("tr:last");                 var $trnew = $trlast.clone();                  var suffix = $trnew.find(':input:first').attr('name').match(/\d+/);                 $trnew.find("td:last").html('<a href="#" class="remove">remove</a>');                 $.each($trnew.find(':input'), function (i, val) {                     // replaced name                     var oldn = $(this).attr('name');                     var newn = oldn.replace('[' + suffix + ']', '[' + (parseint(suffix) + 1) + ']');                     $(this).attr('name', newn);                     //replaced value                     var type = $(this).attr('type');                     if (type.tolowercase() == "text") {                         $(this).attr('value', '');                     }                      // if have type replace default value                     $(this).removeclass("input-validation-error");                  });                 $trlast.after($trnew);                  // re-assign validation                 var form = $("form")                     .removedata("validator")                     .removedata("unobtrusivevalidation");                 $.validator.unobtrusive.parse(form);             });              // 2. remove             $('a.remove').live("click", function (e) {                 e.preventdefault();                 $(this).parent().parent().remove();             });          });     </script> } 

can body me?


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -