faisal23 Ответов: 0

Получить несколько вложенных частичных представлений в MVC


I have one page which contains one multiple partial pages. In each partial view there will be again multiple partial pages. When i am getting this it will add data table to ds contains three tables. how can i show it in hierarchical order??

THis is my DAL


public static ConsignmentNote GetConsignmentNoteByID(int id)
        {
            ConsignmentNote consignmentnote = null;
            SqlConnection sqlConnection = null;
            sqlConnection = SqlConnectionHelper.GetConnectionConnectionString();
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            try
            {
                cmd = new SqlCommand("GetConsignmentNoteByCNNoteId", sqlConnection);
                cmd.Parameters.Add(new SqlParameter("@ConsignmentNoteID", id));
                cmd.CommandType = CommandType.StoredProcedure;
                da.SelectCommand = cmd;
                da.Fill(ds);

                //First table data
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataRow row = ds.Tables[0].Rows[0];
                    consignmentnote = new ConsignmentNote(row);
                }
                else
                {
                    consignmentnote = new ConsignmentNote();
                }

                //Second table data 
                consignmentnote.LstAdditionalCN = new List<AdditionalCN>();
                int rowIndexCN = 1;

                if (ds.Tables[1].Rows.Count > 0)
                {
                    int i = 0;
                    foreach (DataRow acnRow in ds.Tables[i].Rows)
                    {                       

                        AdditionalCN objACN = new AdditionalCN();

                        objACN.ConsignmentNoteRelID = acnRow["ConsignmentNoteRelID"] as Int32? ?? 0;
                        objACN.ConsignmentNoteID = acnRow["ConsignmentNoteID"] as Int32? ?? 0;
                        objACN.ConsignmentNoteNumber = acnRow["ConsignmentNoteNumber"] as string ?? null;
                        objACN.CNDate = acnRow["CNDate"] as DateTime? ?? DateTime.MinValue;
                        objACN.ConsignerID = (acnRow["ConsignerID"] as Int32? ?? 0).ToString();
                        objACN.ConsigneeID = (acnRow["ConsigneeID"] as Int32? ?? 0).ToString();
                        objACN.LocationFrom = acnRow["LocationFrom"] as string ?? null;
                        objACN.LocationTo = acnRow["LocationTo"] as string ?? null;

                        if (rowIndexCN == 1)
                        {
                            //insert to default CNI
                            consignmentnote.ConsignmentNoteRelID = objACN.ConsignmentNoteRelID;
                            consignmentnote.ConsignmentNoteNumber = objACN.ConsignmentNoteNumber;
                        }
                        else
                        {
                            //insert to additional CNI
                            consignmentnote.LstAdditionalCN.Add(objACN);
                        }
                        rowIndexCN++;
                    }
                }

                consignmentnote.LstAdditionalInvoice = new List<AdditionalInvoice>();
                int rowIndexCNInvoice = 1;

                if (ds.Tables[2].Rows.Count > 0)
                {
                    foreach (DataRow acnRow in ds.Tables[2].Rows)
                    {
                        AdditionalInvoice objACN = new AdditionalInvoice();

                        objACN.ConsignmentNoteLineItemID = acnRow["ConsignmentNoteLineItemID"] as Int32? ?? 0;
                        objACN.ConsignmentNoteID = acnRow["ConsignmentNoteID"] as Int32? ?? 0;
                        objACN.ConsignmentNoteRelID = acnRow["ConsignmentNoteRelID"] as Int32? ?? 0;
                        objACN.ProjectPO = (acnRow["ProjectPO"] as Int32? ?? 0).ToString();
                        objACN.InvoiceNum = (acnRow["InvoiceNum"] as Int32? ?? 0).ToString();
                        objACN.InvoiceDate = acnRow["InvoiceDate"] as DateTime? ?? DateTime.MinValue;
                        objACN.Pkgs = acnRow["Pkgs"] as string ?? null;
                        objACN.Description = acnRow["Description"] as string ?? null;

                        objACN.ActualWeight = acnRow["ActualWeight"] as string ?? null;
                        objACN.ChargedWeight = acnRow["ChargedWeight"] as string ?? null;
                        objACN.InvoiceValue = acnRow["InvoiceValue"] as decimal? ?? 0;

                        if (rowIndexCNInvoice == 1)
                        {
                            //insert to default CNI
                            consignmentnote.ConsignmentNoteRelID = objACN.ConsignmentNoteRelID;
                            consignmentnote.ConsignmentNoteID = objACN.ConsignmentNoteID;
                        }
                        else
                        {
                            //insert to additional CNI
                            consignmentnote.LstAdditionalInvoice.Add(objACN);
                        }
                        rowIndexCNInvoice++;
                    }
                }

            }
            catch (Exception x)
            {
                throw x;
            }
            finally
            {

            }
            return consignmentnote;
        }


In my ds three tables come from DB shows particular record. How can i display this??


Это моя главная страница создания:

@using TMS_Models
@model ConsignmentNote

@{
    ViewBag.Title = "Consignment Booking";
}
@{
    List<SelectListItem> VehicalList = new List<SelectListItem>();

    VehicalList.Add(new SelectListItem
    {
        Text = "Supplier",
        Value = "Supplier"
    });
    VehicalList.Add(new SelectListItem
    {
        Text = "Company",
        Value = "Company"
    });
}

<section class="content-header">
    <h1>
        @*NEW CN/LR Booking*@
        Consignment Booking
    </h1>

    <ol class="breadcrumb">
        <li><a href="#"> Home</a></li>
        <li class="active"> Consignment Booking  </li>
    </ol>

    @*<button type="submit" class="btn btn-primary btn-lg btn-flat pull-right">Submit</button>*@
</section>

<section class="content">
    <div class="row">
        <div class="col-xs-12">
            @using (Html.BeginForm("SaveConsignmentNoteDetail", "ConsignmentNote", FormMethod.Post, new { @id = "frmInsertConsignmentNote" }))
            {

                @Html.HiddenFor(model => model.ConsignmentNoteID)
                @Html.HiddenFor(model => model.ConsignmentNoteRelID)
                @Html.HiddenFor(model => model.ConsignmentNoteNumber)

                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">Booking Consignment</h3>
                    </div>
                    <div class="box-body">
                        <div class="col-md-12">
                            <div class="form-group col-md-2 col-sm-6 ">

                                <div class="input-group input-group-sm select-vehicle">
                                    <label>Vehicle</label>
                                    @Html.DropDownListFor(model => model.CompanyVehicle, VehicalList, "-- Select --", htmlAttributes: new { @class = "form-control", @id = "drpcompanyvehical" })

                                </div>
                                @Html.ValidationMessageFor(model => model.CompanyVehicle, "", new { @class = "text-danger" })
                            </div>

                            <div id="supplierVehicleDiv" class="form-group col-md-2 col-sm-6">
                                <label>Vehicle No </label>
                                @Html.TextBoxFor(modelItem => modelItem.VehicleNo, new { @class = "form-control", placeholder = " MH-12 AB 2015", maxlength = "50", @id = "txtSuppVehNo" })
                                @Html.ValidationMessageFor(modelItem => modelItem.VehicleNo, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-2 col-sm-6" id="companyVehicleDiv" style="display:none">
                                <label>Vehicle No </label>
                                @Html.DropDownListFor(modelItem => modelItem.ComapnayVehicleNO, new System.Web.Mvc.SelectList(Model.ObjConsignmentNoteValueList.vehicleList, "CompanyVehicleID", "VehicleNo", Model.ComapnayVehicleNO), "-- Select --", htmlAttributes: new { @class = "form-control", onchange = "onChangeId(this); ", @id = "drpCompVehNo" })
                                @Html.ValidationMessageFor(modelItem => modelItem.ComapnayVehicleNO, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-2 col-sm-6">
                                <label class="txt-resp">Reporting Date Time </label>
                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        
                                    </div>
                                    @Html.TextBoxFor(modelItem => modelItem.ReportingDateTime, "{0:dd/MM/yyyy}", new { @class = "form-control", id = "dpReportingDateTime" })
                                    @*@Html.ValidationMessageFor(modelItem => modelItem.ReportingDateTime, "", new { @class = "text-danger" })*@
                                </div>
                            </div>
                            <div class="form-group col-md-2 col-sm-6">
                                <label> Out Date Time </label>
                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        
                                    </div>
                                    @Html.TextBoxFor(modelItem => modelItem.VehicleOutDateTime, "{0:dd/MM/yyyy}", new { @class = "form-control", id = "dpVehicleOutDateTime" })
                                    @*@Html.ValidationMessageFor(modelItem => modelItem.VehicleOutDateTime, "", new { @class = "text-danger" })*@
                                </div>
                            </div>
                            <div class="form-group col-md-2 col-sm-6" id="companyVehicleTypeDiv">
                                <label>Vehicle Type </label>
                                @Html.TextBoxFor(modelItem => modelItem.VehicleType, new { @class = "form-control", id = "VehicleType", placeholder = "(e.g.) TATA", maxlength = "50" })
                                @Html.ValidationMessageFor(modelItem => modelItem.VehicleType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-2 col-sm-6" id="supplierVehicleTypeDiv" style="display:none">
                                <label>Vehicle Type </label>
                                @Html.DropDownListFor(modelItem => modelItem.SupplierVehicleType, new System.Web.Mvc.SelectList(Model.ObjConsignmentNoteValueList.SupplierVehiclesType, "SupplierVehicleType", "SupplierVehicleType", Model.SupplierVehicleType), htmlAttributes: new { @class = "form-control" })
                            </div>
                            <div class="col-md-2 col-sm-6">
                                <div class="form-group">
                                    <label>Advance Payment </label>
                                    @Html.TextBoxFor(modelItem => modelItem.AdvancePayment, new { @class = "form-control", id = "AdvancePayment", placeholder = "(e.g.) 50000", maxlength = "50", @type = "number" })
                                    @Html.ValidationMessageFor(modelItem => modelItem.AdvancePayment, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="box">

                    <div class="box-body">

                        <div class=" box box-info">
                            <div class="table-responsive col-md-12">
                                <div id="divAdditionalCN0">
                                    @Html.Action("AddAdditionalCN", new { ObjconsignmentNoteCN = Model.LstAdditionalCN[0], index = 0 })
                                </div>
                            </div>
                        </div>

                        <div class="clearfix"></div>
                        <div class="box box-info" id="additionalCNdiv">
                            <h4 class="box-header">Additional Consignment Booking </h4>
                            <div id="divAddAdditional" class="table-responsive col-md-12">
                                @if (Model.LstAdditionalCN != null && Model.LstAdditionalCN.Count > 0)
                                {
                                    for (int i = 1; i < Model.LstAdditionalCN.Count; i++)
                                    {
                                        <div id="divAdditionalCN@(i)">
                                            @Html.Action("AddAdditionalCN", new { ObjconsignmentNoteCN = Model.LstAdditionalCN[i], index = i })
                                        </div>
                                    }
                                }
                            </div>
                            <button type="button" onclick="addAdditionalConsignmentNote();" id="btnAddAdditionalConsignmentNote" class="btn btn-info pull-right btnClick"> CN </button>
                        </div>

                    </div>
                </div>

                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"> Manifesto  </h3>
                    </div>

                    <div class="box-body">
                        <div id="divManifestoCompany" style="display:none">
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>License No.</label>
                                    @Html.TextBoxFor(modelItem => modelItem.CompDriverLicenseNumber, new { @class = "form-control", placeholder = "(e.g.) DL NO. MH-1220050000188" })
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>Driver Name</label>
                                    @Html.TextBoxFor(modelItem => modelItem.CompDriverName, new { @class = "form-control", placeholder = "(e.g.) Aakash" })

                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>Driver Phone1 </label>
                                    @Html.TextBoxFor(modelItem => modelItem.CompDriverPhone1, new { @class = "form-control", placeholder = "(e.g) 9823456780", maxlength = "10" })
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>Driver Phone2 </label>
                                    @Html.TextBoxFor(modelItem => modelItem.CompDriverPhone2, new { @class = "form-control", placeholder = "(e.g.) 8791234567", maxlength = "10", @type = "number" })
                                </div>

                            </div>
                        </div>

                        <div id="divManifestoSupplier">

                            <div class="form-group col-md-3 col-sm-6">
                                <label>Supplier</label>
                                @Html.ValidationMessageFor(modelItem => modelItem.VehicleSupplierID, "", new { @class = "text-danger" })
                                <div class="input-group input-group-sm">
                                    @Html.DropDownListFor(modelItem => modelItem.VehicleSupplierID, new System.Web.Mvc.SelectList(Model.ObjConsignmentNoteValueList.SuppliersList, "SupplierID", "NickName", Model.VehicleSupplierID), "--Select--", htmlAttributes: new { @class = "form-control", @id = "drpsupplierName" })
                                    <span class="input-group-btn">  <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#divAddSupplierNickName">  Add  </button> </span>
                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>Vehicle Owner Name</label>
                                    @Html.TextBoxFor(modelItem => modelItem.OwnerName, new { @class = "form-control", placeholder = "(e.g.) Sachin" })

                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>Vehicle Owner Phone 1</label>
                                    @Html.TextBoxFor(modelItem => modelItem.OwnerPhone1, new { @class = "form-control", placeholder = "(e.g) 9823456780", maxlength = "10" })
                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>Vehicle Owner Phone 2</label>
                                    @Html.TextBoxFor(modelItem => modelItem.OwnerPhone2, new { @class = "form-control", placeholder = "(e.g) 9823456780", maxlength = "10" })
                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>Driver Name</label>
                                    @Html.TextBoxFor(modelItem => modelItem.SuppDriverName, new { @class = "form-control", placeholder = "(e.g.) Aakash" })

                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>Driver Phone 1</label>
                                    @Html.TextBoxFor(modelItem => modelItem.SuppDriverPhone1, new { @class = "form-control", placeholder = "(e.g) 9823456780", maxlength = "10" })
                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>Driver Phone 2</label>
                                    @Html.TextBoxFor(modelItem => modelItem.SuppDriverPhone2, new { @class = "form-control", placeholder = "(e.g) 9823456780", maxlength = "10" })
                                </div>
                            </div>

                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label>License No.</label>
                                    @Html.TextBoxFor(modelItem => modelItem.SuppDriverLicenseNumber, new { @class = "form-control", placeholder = "(e.g.) DL NO. MH-1220050000188" })
                                    @*@Html.ValidationMessageFor(modelItem => modelItem.SuppDriverLicenseNumber, "", new { @class = "text-danger" })*@
                                </div>
                            </div>

                        </div>
                    </div>
                </div>

                <div class="box-footer">
                    <button type="submit" class="btn btn-primary btn-lg btn-flat pull-right">Submit</button>
                </div>
            }

        </div>
    </div>
</section>

<div class="modal fade" id="divAddConsignor" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">

            <!-- Modal Header -->
            <div class="modal-header">
                <h4 class="modal-title">Add Consignor</h4>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>

            <!-- Modal body -->
            <div class="modal-body">
                <div class="table-responsive" id="divConsignorProperties">
                    <!--div for Name of the consignor-->
                    <label for="name">Name</label>
                    <input type="text" id="consignorName" required="required" class="form-control" placeholder="(e.g.) Sachin Mane" maxlength="50" />
                    <br />
                    <!--div for Nick Name of the consignor-->

                    <label for="name">Nick Name</label>
                    <input type="text" id="nickName" required="required" class="form-control" placeholder="(e.g.) Sachin" maxlength="50" />
                    <br />

                    <!--div for Phone Number of the consignor-->
                    <label for="name">Phone number</label>
                    <input type="number" required="required" class="form-control" maxlength="10" id="PhoneNo" placeholder="(e.g) 9823456780" />
                    <br />

                    <!--div for Phone Number of the consignor-->
                    <label for="name">Email</label>
                    <input type="email" required="required" class="form-control" maxlength="50" id="Email" placeholder="(e.g) test@gmail.com" />
                    <br />

                </div>
            </div>

            <!-- Modal footer -->
            <div class="modal-footer">
                <div class="row">
                    <div class="col-md-6">
                        <button type="submit" class="btn btn-info btn-flat" onclick="createConsignor()">Add</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="divAddConsignee" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <h4 class="modal-title">Add Consignee</h4>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>

            <div class="modal-body">
                <div class="table-responsive" id="divConsignorProperties">
                    <label for="name">Name</label>
                    <input type="text" id="consigneeName" required="required" class="form-control" placeholder="(e.g.) Sachin Mane" maxlength="50" />
                    <br />

                    <label for="name">Nick Name</label>
                    <input type="text" id="ConsigneeNickName" required="required" class="form-control" placeholder="(e.g.) Sachin" maxlength="50" />
                    <br />

                    <label for="name">Phone number</label>
                    <input type="number" required="required" class="form-control" maxlength="10" id="ConsigneePhoneNo" placeholder="(e.g) 9823456780" />
                    <br />

                    <label for="name">Email</label>
                    <input type="email" required="required" class="form-control" maxlength="50" id="ConsigneeEmail" placeholder="(e.g) test@gmail.com" />
                    <br />

                </div>
            </div>

            <div class="modal-footer">
                <div class="row">
                    <div class="col-md-6">
                        <button type="submit" class="btn btn-info btn-flat" onclick="createConsignee()">Add</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="divAddCity" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Add City</h4>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>

            <div class="modal-body">
                <div class="table-responsive" id="divConsignorProperties">
                    <label for="name">City Name</label>
                    <input type="text" id="cityName" required="required" class="form-control" placeholder="(e.g.) Pune" maxlength="30" />
                    <br />
                </div>
            </div>

            <div class="modal-footer">
                <div class="row">
                    <div class="col-md-6">
                        <button type="submit" class="btn btn-info btn-flat" onclick="createCity()">Add</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="divAddSupplierNickName" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <h4 class="modal-title">Add Supplier</h4>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>

            <div class="modal-body">
                <div class="table-responsive" id="divSupplierProperties">
                    <label for="name">Name</label>
                    <input type="text" id="supplierName" required="required" class="form-control" placeholder="(e.g.) Sachin Mane" maxlength="50" />
                    <br />

                    <label for="name">Nick Name</label>
                    <input type="text" id="supplierNickName" required="required" class="form-control" placeholder="(e.g.) Sachin" maxlength="50" />
                    <br />

                    <label for="name">Phone number</label>
                    <input type="number" required="required" class="form-control" maxlength="10" id="supplierPhoneNo" placeholder="(e.g) 9823456780" />
                    <br />

                    <label for="name">Email</label>
                    <input type="email" required="required" class="form-control" maxlength="50" id="supplierEmail" placeholder="(e.g) test@gmail.com" />
                    <br />

                </div>
            </div>

            <div class="modal-footer">
                <div class="row">
                    <div class="col-md-6">
                        <button type="submit" class="btn btn-info btn-flat" onclick="createSupplier()">Add</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts{

    <script type="text/javascript">
        var addcountCN = @(Model.LstAdditionalCN==null?0: Model.LstAdditionalCN.Count);
        var addcountInv = @(Model.LstAdditionalInvoice==null?0: Model.LstAdditionalInvoice.Count);

        function onChangeId($this) {
            var companyVehicleID = $($this).val();
            if (companyVehicleID != undefined && companyVehicleID != null) {
                $.ajax({
                    url: '/ConsignmentNote/GetVehicleTypeByID',
                    type: 'POST',
                    datatype: 'application/json',
                    contentType: 'application/json',
                    data: JSON.stringify({ companyVehicleID: companyVehicleID }),
                    success: function (result) {
                        if (result != undefined && result != null && result.Status != null) {
                            $("#VehicleType").val(result.Status);
                        }

                    },
                    error: function () { alert("Whooaaa! Something went wrong..") },
                });
            }
        }

        var $currDrpdn;
        $(document).ready(function () {
            $('#frmInsertConsignmentNote').on('click', 'button[data-target][data-toggle]', function () {
                $btn = $(this);
                $currDrpdn = $btn.closest('div').find('select');
            });

            //to add invoice details
            addRow(this);

            $("#drpcompanyvehical").change(function () {
                showHideManifestoOn_CompSuppVehicalChange();
            });

            showHideManifestoOn_CompSuppVehicalChange();

            $(document).on("focus", "#dpRegistrationDate", function () { $(this).datepicker(); });

            $(document).on("focus", "#invoiceDate", function () { $(this).datepicker(); });

            $('#frmInsertConsignmentNote').submit(function () {
                //below code used to skip validation on action method

                if ($(this).valid()) {
                    if ($('#drpcompanyvehical').val() == 'Supplier') {
                        $('#drpCompVehNo option:first').attr('value', '0');
                    } else if ($('#drpcompanyvehical').val() == 'Company') {
                        $('#txtSuppVehNo').val('No Data');
                        $('#drpsupplierName option:first').attr('value', '0');
                    }
                }
            });

        });

        $(function () {
            var today = new Date();


            $('#dpReportingDateTime').datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy',
                autoclose: true
            }).on('changeDate', function (ev) {
                $(this).datepicker('hide');
                $('#dpVehicleOutDateTime').datepicker("setDate", ev.date);
                $('#dpRegistrationDate').datepicker("setDate", ev.date);
                $('#invoiceDate').datepicker("setDate", ev.date);
            }).datepicker("setDate", today);

            $('#dpVehicleOutDateTime').datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy',
                autoclose: true
            }).on('changeDate', function (ev) {
                $(this).datepicker('hide');
                $('#dpRegistrationDate').datepicker("setDate", ev.date);
                $('#invoiceDate').datepicker("setDate", ev.date);
                }).datepicker("setDate", today);

            $('#dpRegistrationDate').datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy',
                autoclose: true,
            }).on('changeDate', function (ev) {
                $(this).datepicker('hide');
                $('#invoiceDate').datepicker("setDate", ev.date);
            }).datepicker("setDate", today);

            $('#invoiceDate').datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy',
                autoclose: true,
            }).on('changeDate', function (ev) {
                $(this).datepicker('hide');
            }).datepicker("setDate", today);
        });

        function addAdditionalConsignmentNote($this) {

            var addcountCN = $($this).prev().find('div[data-cn]').length + 1;

            $("#divAddAdditional").append('<div id="divAdditionalCN' + addcountCN + '"></div>');

            var param = { ConsignerID: $('#drpConsignorName').val(), ConsigneeID: $('#drpConsigneeName').val(), CNDate: $('#dpRegistrationDate').val(), LocationFrom: $('#drpDownFrom').val(), LocationTo: $('#drpDownTo').val(), index: addcountCN };

            $("#divAdditionalCN" + addcountCN).load('@Url.Action("AddAdditionalCN", "ConsignmentNote")', param);

            addcountCN++;
        }

        function addAdditionalInv($this) {
            var $btn = $($this);

            var $divCNMain = $btn.closest('div[data-cn]');
            var $divAdditionalInv = $divCNMain.find('#divAddAdditionalInv');

            var addcountInv = parseInt($divAdditionalInv.find('div[data-invoice]').last().find('#hdnInvIndex').val())+ 1;
            var currCnIndex = $divCNMain.find('#hdnCnIndex').val();
            
            var param = { InvoiceDate: $('#dpRegistrationDate').val(), cnindex: currCnIndex ,  index: addcountInv };
            
            getPartialPageData('AddAdditionalInvoice', 'ConsignmentNote', param, function (data) {
                $divAdditionalInv.append(data);
            }, true);
        }

        function showHideManifestoOn_CompSuppVehicalChange() {
            var val = $('#drpcompanyvehical').val();
            if (val == "Company") {
                $("#divManifestoSupplier").hide('slow');
                $("#divManifestoCompany").show();
                $("Div#supplierVehicleDiv").hide();
                $("#companyVehicleDiv").show();
                $("#companyVehicleTypeDiv").show();
                //$("#VehicleType").val('');
                $("#supplierVehicleTypeDiv").hide();

            } else {
                //$("select#ComapnayVehicleNO").change();
                $("#companyVehicleDiv").hide();
                $("Div#supplierVehicleDiv").show();
                $("#divManifesto").show();
                $("#divManifestoCompany").hide('slow');
                $("#divManifestoSupplier").show();
                $("#companyVehicleTypeDiv").hide();
                $("#supplierVehicleTypeDiv").show();

            }
        }

        function createConsignor() {
            var name = $("#consignorName").val();
            var nickName = $("#nickName").val();
            var phone = $("#PhoneNo").val();
            var email = $("#Email").val();
            var regex = /^([\w-\.]+@@([\w-]+\.)+[\w-]{2,4})?$/;
            if (name === "") {
                showErrorBar("Name required");
                return false;
            }

            if (nickName === "") {
                showErrorBar("NickName required");
                return false;
            }

            if (phone === "") {
                showErrorBar("Phone no required");
                return false;
            }
            if (phone.length != 10) {
                showErrorBar("Please enter 10 digit mobile no.");
                return false;
            }

            if (email === "") {
                showErrorBar("Email required");
                return false;

            }
            if (!regex.test(email)) {
                showErrorBar("Valid Email required");
                return false;
            }

            var consignor = {
                Name: name,
                NickName: nickName,
                PhoneOne: phone,
                Email: email
            };

            $.ajax({
                url: '/ConsignmentNote/SaveConsigner',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({ consignor: consignor }),
                success: function (result) {
                    if (result != undefined && result != false && result.NickName != null) {
                        var $opt = $('<option></option>').val(result.id).html(result.NickName);

                        $("#frmInsertConsignmentNote").find("select#drpConsignorName").append($opt);

                        $currDrpdn.find('option:last').prop('selected', true);

                        $("button.close").click();
                    }
                },
                error: function () { showErrorBar("Whooaaa! Something went wrong..") },
            });
        }

        function createConsignee() {
            var name = $("#consigneeName").val();
            var nickName = $("#ConsigneeNickName").val();
            var phone = $("#ConsigneePhoneNo").val();
            var email = $("#ConsigneeEmail").val();
            var regex = /^([\w-\.]+@@([\w-]+\.)+[\w-]{2,4})?$/;

            if (name === "") {
                showErrorBar("Name required");
                return false;
            }

            if (nickName === "") {
                showErrorBar("NickName required");
                return false;
            }

            if (phone === "") {
                showErrorBar("Phone no required");
                return false;
            }
            if (phone.length != 10) {
                showErrorBar("Please enter 10 digit mobile no.");
                return false;
            }

            if (email === "") {
                showErrorBar("Email required");
                return false;

            }
            if (!regex.test(email)) {
                showErrorBar("Valid Email required");
                return false;
            }

            var consignee = {
                Name: name,
                NickName: nickName,
                PhoneOne: phone,
                Email: email
            };

            $.ajax({
                url: '/ConsignmentNote/SaveConsignee',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({ consignee: consignee }),
                success: function (result) {
                    if (result != undefined && result != false && result.NickName != null) {
                        $("#frmInsertConsignmentNote").find("select#drpConsigneeName").append($('<option></option>').val(result.id).html(result.NickName));
                        $currDrpdn.find('option:last').prop('selected', true);
                        $("button.close").click();
                    }
                },
                error: function () { showErrorBar("Whooaaa! Something went wrong..") },
            });
        }

        function createCity() {
            var cityName = $("#cityName").val();

            if (cityName === "") {
                showErrorBar("City Name required");
                return false;
            }
            if (cityName.length < 2) {
                showErrorBar("City Name can not less than two character");
                return false;
            }

            $.ajax({
                url: '/ConsignmentNote/SaveCity',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({ CityName: cityName }),
                success: function (result) {
                    if (result != undefined && result != false && result.CityName != null) {
                        $("#frmInsertConsignmentNote").find("select#drpDownTo,select#drpDownFrom").append($('<option></option>').val(result.id).html(result.CityName));
                        $currDrpdn.find('option:last').prop('selected', true);

                        $("button.close").click();
                    }
                }
            });

        }

        function createSupplier() {

            var name = $("#supplierName").val();
            var nickName = $("#supplierNickName").val();
            var phone = $("#supplierPhoneNo").val();
            var email = $("#supplierEmail").val();

            if (name === "") {
                showErrorBar("Name required");
                return false;
            }

            if (nickName === "") {
                showErrorBar("NickName required");
                return false;
            }

            if (phone === "") {
                showErrorBar("Phone no required");
                return false;
            }

            if (email === "") {
                showErrorBar("Email required");
                return false;
            }

            var supplier = {
                Name: name,
                NickName: nickName,
                PhoneOne: phone,
                Email: email
            };

            $.ajax({
                url: '/ConsignmentNote/SaveSupplier',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({ supplier: supplier }),
                success: function (result) {
                    if (result != undefined && result != false && result.NickName != null) {
                        var mySelect = $("#drpsupplierName");
                        mySelect.append($('<option selected></option>').val(result.id).html(result.NickName));

                        $("button.close").click();
                    }
                },
                error: function () { showErrorBar("Whooaaa! Something went wrong..") },
            });
        }

        function bindDataTypes() {
            $('td[data-field=Actual] input').attr('type', 'number');
            $('td[data-field=Charged] input').attr('type', 'number');
            $('td[data-field=InvoiceNO] input').attr('type', 'number');
            $('td[data-field=InvoiceValue] input').attr('type', 'number');
            $('td[data-field=InvoiceDate] input').datepicker({ format: 'dd-MM-yy', autoclose: true }).on('changeDate', function (ev) {
                $(this).datepicker('hide');
            }).attr('readonly', 'true');
        }

        function removeRow($this) {
            showConfirmationBar("Remove invoice?", "Are you sure you want to remove this invoice ?", "OK", "Cancel", "");
            $("#OK").unbind('click');
            $("#OK").bind('click', function () {
                $($this).closest('tr').remove();
                if ($("#consignmentDivTableBody").find('tr').length == 0) {
                    var $newTr = $(document.createElement('tr'));
                    $newTr.attr('id', 'norecords');
                    $newTr.html('<td colspan="9">No records found</td>');
                    $newTr.appendTo("#consignmentDivTableBody");
                }
                $("#ConfirmationBar").hide();
            });
            $("#Cancel").unbind('click');
            $("#Cancel").bind('click', function () {
                var confBar = document.getElementById("ConfirmationBar");
                confBar.style.display = 'none';
            });
            return false;
        }

        function removeRow($this) {

            $($this).closest('tr').remove();
            if ($("#consignmentDivTableBody").find('tr').length == 0) {
                var $newTr = $(document.createElement('tr'));
                $newTr.attr('id', 'norecords');
                $newTr.html('<td colspan="9">No records found</td>');
                $newTr.appendTo("#consignmentDivTableBody");
            }
        }

        function addRow($this) {
            if ($("tr#norecords").length > 0) {
                $("tr#norecords").remove();
            }
            var $newTr = $(document.createElement('tr'));
            $newTr.attr('data-id', '1');
            $newTr.html('<td data-field="Project"></td>' +
                '<td data-field="InvoiceNO"></td>' +
                '<td data-field="InvoiceDate"></td>' +
                '<td data-field="Package"></td>' +
                '<td data-field="Description"></td>' +
                '<td data-field="Actual"></td>' +
                '<td data-field="Charged"></td>' +
                '<td data-field="InvoiceValue"></td>' +
                '<td class="text-right">' +
                '<a class="btn btn-default btn-xs edit"> </a>' +
                '<a class="btn btn-default btn-xs" onclick="removeRow(this)"> </a>');

            $newTr.appendTo("#consignmentDivTableBody");
            bindEditablePlugin();
        }

        function unbindDataTypes() {
            $('td[data-field=InvoiceDate] input').datepicker("destroy");
        }

        function bindEditablePlugin() {
            $('tbody tr').editable({
                keyboard: true,
                dblclick: true,
                button: true,
                buttonSelector: ".edit",
                maintainWidth: true,
                dropdowns: {
                    // sex: ['Male', 'Female']
                },
                edit: function (values) {
                    $(".edit i", this).removeClass('fa-pencil').addClass('fa-save').attr('title', 'Save');
                    bindDataTypes();
                },
                save: function (values) {
                    $(".edit i", this).removeClass('fa-save').addClass('fa-pencil').attr('title', 'Edit');
                    var id = $(this).data('id');
                    var value = values;
                    unbindDataTypes();
                },
                remove: function (values) {
                    unbindDataTypes();
                },
                cancel: function (values) {
                    $(".edit i", this).removeClass('fa-save').addClass('fa-pencil').attr('title', 'Edit');
                    unbindDataTypes();
                }
            });
        }

        function deleteCurrentCN($btn) {
            showConfirmationBar("Remove Additional Booking Consignment?", "Are you sure you want to remove this additional booking consignment ?", "OK", "Cancel", "");
            $("#OK").unbind('click');
            $("#OK").bind('click', function () {
                $btn = $($btn);
                $btn.closest('div[data-invoice]').remove();
                $("#ConfirmationBar").hide();
            });
            $("#Cancel").unbind('click');
            $("#Cancel").bind('click', function () {
                var confBar = document.getElementById("ConfirmationBar");
                confBar.style.display = 'none';
            });
            return false;
        }
    </script>

}


Это родительская часть страницы:

@using TMS_Models
@model AdditionalCN
@{
    ConsignmentNoteValueList ObjConsignmentNoteValueList = ViewBag.ObjConsignmentNoteValueList;
}

<section>
    @*<button type="button" onclick="deleteCurrentCN(this)" class="btn btn-danger btn-flat btninfo pull-right"> Delete </button>*@
    <div class="row">

        <div class="box-body box-info box-body-padding">
            <div class=" col-md-12" data-cn="true">
                <div class="form-group col-md-2 col-sm-6">
                    <label for="name">CN No</label>
                    <input type="hidden" id="hdnCnIndex" name="LstAdditionalCN.index" value="@ViewBag.index" />
                    @Html.HiddenFor(p => p.ConsignmentNoteID, new { name = "LstAdditionalCN[" + ViewBag.index + "].ConsignmentNoteID" })
                    @Html.HiddenFor(p => p.ConsignmentNoteRelID, new { name = "LstAdditionalCN[" + ViewBag.index + "].ConsignmentNoteRelID" })

                    @Html.TextBoxFor(modelItem => modelItem.ConsignmentNoteNumber, new { @class = "form-control", Name = "LstAdditionalCN[" + ViewBag.index + "].ConsignmentNoteNumber", placeholder = "1234567", maxlength = "50", @type = "number" })
                    @Html.ValidationMessageFor(modelItem => modelItem.ConsignmentNoteNumber, "", new { @class = "text-danger" })
                </div>
                <div class="form-group col-md-2">
                    <label>Date </label>
                    <div class="input-group date">
                        <div class="input-group-addon">
                            
                        </div>
                        @Html.TextBoxFor(modelItem => modelItem.CNDate, "{0:dd/MM/yyyy}", new { @class = "form-control", Name = "LstAdditionalCN[" + ViewBag.index + "].CNDate", id = "dpRegistrationDate", })
                        @*@Html.ValidationMessageFor(modelItem => modelItem.CNDate, "", new { @class = "text-danger" })*@
                    </div>
                </div>
                <div class="form-group col-md-2 col-sm-6">
                    <label for="name">Consignor Nick Name</label>
                    <div class="input-group input-group-sm">
                        @Html.DropDownListFor(modelItem => modelItem.ConsignerID, new System.Web.Mvc.SelectList(ObjConsignmentNoteValueList.ConsignorNameList, "ConsignorID", "NickName", Model.ConsignerID), "--Select--", htmlAttributes: new { @class = "form-control", Name = "LstAdditionalCN[" + ViewBag.index + "].ConsignerID", @id = "drpConsignorName" })
                        <span class="input-group-btn">  <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#divAddConsignor">  </button> </span>
                    </div>
                </div>
                <div class="form-group col-md-2 col-sm-6">
                    <label for="">Consignee Nick Name</label>
                    <div class="input-group input-group-sm">
                        @Html.DropDownListFor(modelItem => modelItem.ConsigneeID, new System.Web.Mvc.SelectList(ObjConsignmentNoteValueList.ConsigneeNameList, "ConsigneeID", "NickName", Model.ConsigneeID), "--Select--", htmlAttributes: new { @class = "form-control", Name = "LstAdditionalCN[" + ViewBag.index + "].ConsigneeID", @id = "drpConsigneeName" })
                        <span class="input-group-btn">   <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#divAddConsignee"> </button> </span>
                    </div>
                </div>
                <div class="form-group col-md-2 col-sm-6">
                    <label for="customerNo">Location From</label>
                    <div class="input-group input-group-sm">
                        @Html.DropDownListFor(modelItem => modelItem.LocationFrom, new System.Web.Mvc.SelectList(ObjConsignmentNoteValueList.CitiesList, "CityID", "CityName", Model.LocationFrom), "--Select--", htmlAttributes: new { @class = "form-control", Name = "LstAdditionalCN[" + ViewBag.index + "].LocationFrom", @id = "drpDownFrom" })
                        <span class="input-group-btn">  <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#divAddCity"> </button> </span>
                    </div>
                </div>
                <div class="form-group col-md-2 col-sm-6">
                    <label for="customerNo">Location To</label>
                    <div class="input-group input-group-sm">

                        @Html.DropDownListFor(modelItem => modelItem.LocationTo, new System.Web.Mvc.SelectList(ObjConsignmentNoteValueList.CitiesList, "CityID", "CityName", Model.LocationTo), "--Select--", htmlAttributes: new { @class = "form-control", Name = "LstAdditionalCN[" + ViewBag.index + "].LocationTo", @id = "drpDownTo" })
                        <span class="input-group-btn">  <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#divAddCity"> </button> </span>
                    </div>
                </div>

                <div id="divAddAdditionalInv0" class="table-responsive col-md-12">
                </div>

                <div id="divAddAdditionalInv" class="table-responsive col-md-12">
                    @Html.Action("AddAdditionalInvoice", new { ObjconsignmentNote = 0, cnindex = ViewBag.index, index = 0 })

                    @if (Model.LstAdditionalInvoice != null && Model.LstAdditionalInvoice.Count > 0)
                    {
                        for (int i = 1; i < Model.LstAdditionalInvoice.Count; i++)
                        {
                            @Html.Action("AddAdditionalInvoice", new { ObjconsignmentNote = Model.LstAdditionalInvoice[i], cnindex = ViewBag.index, index = i })
                        }
                    }
                </div>

                <button type="button" onclick="addAdditionalInv(this);" id="btnAddAdditionalInvoice" class="btn btn-info pull-right btnClick">
                    
                    Invoice
                </button>

            </div>
        </div>

    </div>
</section>

@section  scripts{
    <script type="text/javascript">

    </script>
}


А это ребенок частичная страница:

@using TMS_Models
@model AdditionalInvoice

@{
    ConsignmentNoteValueList ObjConsignmentNoteValueList = ViewBag.ObjConsignmentNoteValueList;
}

<section>
    <div class="row">
        <div>
            <div>
                <div class="box-body box-body-padding">

                    <div class="col-md-12" data-invoice="true">
                        <div class="form-group col-md-1 col-sm-6">
                            <label for="name">Project/PO</label>
                            <input type="hidden" name="LstAdditionalInvoice.index" value="@ViewBag.index" />
                            @{ var ind = ViewBag.index;
                                var cnind = ViewBag.cnindex;
                            }
                            <input type="hidden" id="hdnInvIndex" name="LstAdditionalCN[@ViewBag.cnindex].LstAdditionalInvoice.index" value="@ind" />

                            @Html.HiddenFor(p => p.ConsignmentNoteRelID, new { Name = "LstAdditionalCN[" + ViewBag.cnindex + "].LstAdditionalInvoice[" + ViewBag.index + "].ConsignmentNoteRelID" })
                            @Html.TextBoxFor(modelItem => modelItem.ProjectPO, new { Name = "LstAdditionalCN[" + ViewBag.cnindex + "].LstAdditionalInvoice[" + ViewBag.index + "].ProjectPO", @class = "form-control", placeholder = "", maxlength = "30" })
                        </div>
                        <div class="form-group col-md-2 col-sm-6">
                            <label for="name" >Invoice No</label>
                            @Html.TextBoxFor(modelItem => modelItem.InvoiceNum, new { Name = "LstAdditionalCN[" + ViewBag.cnindex + "].LstAdditionalInvoice[" + ViewBag.index + "].InvoiceNum", Value = Model.InvoiceNum == null ? "" : Model.InvoiceNum.ToString(), @class = "form-control", placeholder = "", maxlength = "30" })
                        </div>

                        <div class="form-group col-md-2 col-sm-6">
                            <label>Invoice Date </label>
                            <div class="input-group date">
                                <div class="input-group-addon">
                                    
                                </div>
                                @Html.TextBoxFor(modelItem => modelItem.InvoiceDate, "{0:dd/MM/yyyy}", new { @class = "form-control", Name = "LstAdditionalCN[" + ViewBag.cnindex + "].LstAdditionalInvoice[" + ViewBag.index + "].InvoiceDate", id = "invoiceDate", @value = DateTime.Now.ToShortDateString() })
                            </div>
                        </div>
                        <div class="form-group col-md-1 col-sm-6">
                            <label for="name">Pkgs</label>
                            @Html.TextBoxFor(modelItem => modelItem.Pkgs, new { @class = "form-control", placeholder = "", maxlength = "30", Name = "LstAdditionalCN[" + ViewBag.cnindex + "].LstAdditionalInvoice[" + ViewBag.index + "].Pkgs" })
                        </div>
                        <div class="form-group col-md-1 col-sm-6">
                            <label for="name">Description</label>
                            @Html.TextBoxFor(modelItem => modelItem.Description, new { @class = "form-control", placeholder = "", maxlength = "30", Name = "LstAdditionalCN[" + ViewBag.cnindex + "].LstAdditionalInvoice[" + ViewBag.index + "].Description" })
                        </div>
                        <div class="form-group col-md-1 col-sm-6">
                            <label for="name">Actual wt</label>
                            @Html.TextBoxFor(modelItem => modelItem.ActualWeight, new { @class = "form-control", placeholder = "", maxlength = "30", Name = "LstAdditionalCN[" + ViewBag.cnindex + "].LstAdditionalInvoice[" + ViewBag.index + "].ActualWeight" })
                        </div>
                        <div class="form-group col-md-1 col-sm-6">
                            <label for="name" class="txt-font-charg">Charged wt</label>
                            @Html.TextBoxFor(modelItem => modelItem.ChargedWeight, new { @class = "form-control", placeholder = "", maxlength = "30", Name = "LstAdditionalCN[" + ViewBag.cnindex + "].LstAdditionalInvoice[" + ViewBag.index + "].ChargedWeight" })
                        </div>
                        <div class="form-group col-md-2 col-sm-6">
                            <label for="name">Invoice Value</label>
                            @Html.TextBoxFor(modelItem => modelItem.InvoiceValue, new { Value = Model.InvoiceValue == 0 ? "" : Model.InvoiceValue.ToString(), @class = "form-control", placeholder = "", maxlength = "30", Name = "LstAdditionalCN[" + ViewBag.cnindex + "].LstAdditionalInvoice[" + ViewBag.index + "].InvoiceValue" })
                        </div>


                        <button type="button" onclick="deleteCurrentCN(this)" style="margin-top: 24px;" class="btn btn-danger btn-flat btninfo pull-right"> </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

@section  scripts{
    <script type="text/javascript">

    </script>
}


Что я уже пробовал:

Я пробовал использовать loop и lst, но я новичок в MVC, поэтому я не могу получить его должным образом

David_Wimbley

Можете ли вы также добавить часть вашего кода html/razor/cshtml, чтобы мы могли видеть, что вы попытались сделать?

faisal23

Привет Дэвид,

Я добавил страницы cshtml.

0 Ответов