如何从中继器获取数据?

时间:2019-08-02 17:07:37

标签: json asp.net-mvc api c#-4.0 jquery.repeater

我正在创建包含多个产品的菜单。首先,我选择早餐,午餐还是特别优惠,然后选择优惠的可用日期。 这个想法是在给定的一天创建菜单时能够一次添加多个产品,因此我使用了一个中继器。 我想将数据传递给API,但是我不知道如何获得中继器中的部件。

https://imgur.com/a/QtxNQLf

这是我的查看代码:

<div class="container" ">
    <div class="form-group">
    <!-- Repeater Html Start -->
    <div class="form-row">
        <div class="col">
            @Html.LabelFor(model => model.Menu.typeID, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.Menu.typeID, new SelectList(Model.Types, "typeID", "Name", "Select Menu Type"), new { @class = "form-control data" })
                @Html.ValidationMessageFor(model => model.Menu.typeID, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="col">
            @Html.LabelFor(model => model.Menu.Date, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Menu.Date, new { htmlAttributes = new { @class = "form-control datetimepicker data" } })
                @Html.ValidationMessageFor(model => model.Menu.Date, "", new { @class = "text-danger" })
            </div>
        </div>
    </div>
    </br>
    <div class="form-row">
        <div id="repeater" class="col">
            <!-- Repeater Heading -->
            <div class="repeater-heading">
                <button class="btn repeater-add-btn">
                    Add Product
                </button>
            </div>
            <div class="clearfix"></div>
            <!-- Repeater Items -->
            <div class="items" data-group="test">
                <!-- Repeater Content -->
                <div class="item-content form-row">
                    <div class="col">
                        @Html.LabelFor(model => model.Menu.productID, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            @Html.DropDownListFor(model => model.Menu.productID, new SelectList(Model.Products, "productID", "productName", "Select Product"), new { @class = "form-control data"})
                            @Html.ValidationMessageFor(model => model.Menu.productID, "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="col">
                        @Html.LabelFor(model => model.Menu.Stock, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            @Html.EditorFor(model => model.Menu.Stock, new { htmlAttributes = new { @class = "form-control data" } })
                            @Html.ValidationMessageFor(model => model.Menu.Stock, "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="pull-right repeater-remove-btn col">
                        <button class="btn btn-danger remove-btn">
                            Remove
                        </button>
                    </div>
                </div>
                <!-- Repeater Remove Btn -->

                <div class="clearfix"></div>
            </div>
        </div>
        <!-- Repeater End -->

    </div>
    </div>

    <div class="form-row">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" id="update" class="btn btn-success" />
        </div>
    </div>

</div>

所以基本上,我需要将转发器数据与Menu模型的typeID和Date属性结合起来,以便将它们存储到数据库中。

0 个答案:

没有答案