2011-06-22 60 views

回答

2

使用Razor作为视图引擎不会使过程更简单,更具可读性。即使使用ASP.NET MVC 3,你也不得不遵循你提到的Editing a variable length list文章。

当然,您可以在jQuery中完全动态地添加一行新的字段,而无需为其创建操作方法。喜欢的东西:

<div id="fields"> 
    <span class="row"> 
     <input type="text" /> 
     <input type="text" /> 
    </span> 
</div> 

<a id="add" href="#">Add another</a> 

<script type="text/javascript"> 

    $(document).ready(function() { 
     $("#add").click(function() { 
      AddTextBox(); 
     }); 
    }); 

    function AddTextBox() { 
     // clone the last span 
     var newRow = $("#fields .row:last").clone(); 
     //clear any value the fields might have 
     $("input", newRow).val(""); 
     //append it to the container div 
     $("#fields").append(newRow); 
    } 
</script> 

尽管如此,在博客张贴的解决方案封装中是相当干净的部分视场的一个新行。

+0

谢谢,将调查此..并更新此帖。 – subseven

相关问题