如何捕获其他模型的局部视图的表数据发送到控制器

时间:2017-11-28 08:58:16

标签: asp.net entity-framework asp.net-mvc-5

我已经通过部分视图和javascript检索了一些数据。 我用javascript开发了一个表。现在我想要捕获那些表数据。该表的数据来自其他模型。我正在使用MVC 5实体框架。如何捕获这些数据以发送控制器? 我需要从表中捕获来自不同模型的数据。该怎么办? 我的代码是:

@model PSMSEntity.trans_master_del
@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Create</h2>


@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $(".add-row").click(function () {
            //var sl = 0;
            var Br_name = $("#Br_Id option:selected").text();
            var Br_Id = $("#Br_Id option:selected").val();
            var item_name = $("#item_code option:selected").text();
            var item_code = $("#item_code option:selected").val();
            var rate = $("#rate").val();
            var quantity = $("#quantity").val();
            if (Br_Id != '' || item_code != '' || rate != '' || quantity != '') {

                var markup = "<tr><td><input type='checkbox' name='record'></td><td>" + Br_name + "<input type='hidden' name='Br_Id' value='" + Br_Id + "'/></td><td>" + item_name + "<input type='hidden' name='item_code' value='" + item_code + "'/></td><td>" + rate + "</td><td>" + quantity + "</td></tr>";
                $("table tbody").append(markup);
                //sl = sl + 1;
            } else { alert('Invalid input');}
        });

        // Find and remove selected table rows
        $(".delete-row").click(function(){
            $("table tbody").find('input[name="record"]').each(function(){
                if($(this).is(":checked")){
                    $(this).parents("tr").remove();
                }
            });
        });

        $(".view-row").click(function () {
            $("table tbody").find('input[name="record"]').each(function () {
                if ($(this).is(":checked")) {
                    //$(this).parents("tr").remove();
                    var br = $('input[name="Br_Id"]').val();
                    var item = $('input[name="item_code"]').val();
                    alert(br +'-'+ item);
                }
            });
        });
        $("#Br_Id").change(function () {

            $("#itemForm").show();
        });
        $("#itemForm").hide();
    });
    </script>






    <div class="form-horizontal">

        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @*<div class="form-group">
            @Html.LabelFor(model => model.trans_del_id, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.EditorFor(model => model.trans_del_id, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.trans_del_id, "", new { @class = "text-danger" })
            </div>
        </div>*@

        <div class="form-group">
            @Html.LabelFor(model => model.Br_Id, "Branch Name", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4">
                @Html.DropDownList("Br_Id", null,"Select Branch", htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Br_Id, "", new { @class = "text-danger" })
            </div>
        </div>



@Html.Partial("trans_details_del")

            <div class="form-group">

                <form>
                    @*<input type="text" id="name" placeholder="Name">
                    <input type="text" id="email" placeholder="Email Address">*@
                    <hr />
                    <input type="button" class="add-row" value="Add Row">
                    <button type="button" class="delete-row">Delete Row</button>
                    <button type="button" class="view-row">View Row</button>
                    <hr />
                </form>






                <form>
                    <div class="row">
                        <div class="col-sm-12 col-md-12">
                            <div class="panel panel-default">
                                <div class="panel-heading no-collapse">Data Table</div>
                                <table class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th>Select</th>
                                            <th>Item name</th>
                                            <th>Rate</th>
                                            <th>Quantity</th>
                                        </tr>
                                    </thead>

                                </table>
                            </div>
                        </div>
                    </div>
                </form>


            </div>

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Create" class="btn btn-default" />
                </div>
            </div>
        </div>
}

@*<div>
    @Html.ActionLink("Back to List", "Index")
</div>*@

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

0 个答案:

没有答案