【问题标题】:create/insert multiple entities simultaneously on one view page在一个视图页面上同时创建/插入多个实体
【发布时间】:2011-09-20 04:59:05
【问题描述】:

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-3


    【解决方案1】:

    使用 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>
    

    不过,博文中的解决方案还是在局部视图中封装了一行新字段,相当简洁。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      相关资源
      最近更新 更多