Когда я нажимаю кнопку Сохранить, соответствующий метод срабатывает, но значение не передается из вида в контроллер. Любое тело, пожалуйста, помогите мне?
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" /> <script src="~/scripts/jquery-1.12.4.js"></script> <script src="~/scripts/bootstrap.min.js"></script> <script src="~/scripts/jquery-ui-1.12.0.js"></script> @*<script src="~/scripts/Custom/ItemReceiveDetils.js"></script>*@ <script src="~/scripts/Extenstion/Numeric/numeric.js"></script> <body> <div class="form-horizontal"> <div class="panel panel-primary"> <div class="panel-heading text-uppercase"> item receive </div> <div class="panel-body"> <div class="row col-md-12"> <div class="col-md-6"> <div class="form-group"> <label class="col-md-3 control-label">Serial No:</label> <div class="col-md-9"> <input type="text" data-member="SerialNo" class="form-control" id="serialNo" placeholder="Name"> </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Name:</label> <div class="col-md-9"> <input class="form-control" type="text" data-member="Name" /> </div> </div> <div class="form-group"> <label class="col-md-3 control-label" style="padding:inherit;margin-top: 6px;">Supplier Price:</label> <div class="col-md-3"> <input class="form-control numbersOnly" type="text" data-member="SupplierPrice" /> </div> <label class="col-md-2 control-label" style="padding:inherit;margin-top: 6px;width:20%;">Cost Price:</label> <div class="col-md-3"> <input class="form-control numbersOnly" type="text" data-member="CostPrice" /> </div> </div> <div class="form-group"> <input type="button" class="col-md-offset-9 col-md-2 btn btn-primary" value="Add" id="add" /> </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="col-md-4 control-label">Challan No:</label> <div class="col-md-8"> <input class="form-control" type="text" data-member="ChallanNo" /> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">Added Date:</label> <div class="col-md-8"> <input class="form-control" type="text" data-member="AddedDate" id="AddedDate" /> </div> </div> <div class="form-group"> <label class="col-md-4 control-label" style="padding:inherit;margin-top: 6px;">Selling Price:</label> <div class="col-md-3"> <input class="form-control numbersOnly" type="text" data-member="SellingPrice" /> </div> <label class="col-md-2 control-label" style="padding:inherit;margin-top: 6px;">Quantity:</label> <div class="col-md-3"> <input class="form-control numbersOnly" type="text" data-member="Quantity" /> </div> </div> <div class="form-group"> <input type="button" class="col-md-offset-9 col-md-2 btn btn-primary" value="Save" id="Save" /> </div> </div> </div> <div class="row col-md-12"> <span class="p">Item List</span> <div class="table-responsive"> <table class="table table-bordered"> <thead> <tr> <th>Name</th> <th>Qty</th> <th>Supplier Price</th> <th>Cot Price</th> <th>Selling Price</th> <th>Action</th> </tr> </thead> <tbody id="tableBody"></tbody> </table> </div> </div> </div> </div> </div> </body> @*<script> $('#AddedDate').datepicker(); </script>*@ <script> $('#AddedDate').datepicker(); $(document).ready(function () { $('.numbersOnly').keyup(function () { this.value = this.value.replace(/[^0-9\.]/g, ''); }); var alldata; var itemlist = []; var supplierPrice = 0; var costPrice = 0; var SellingPrice = 0; var qty = 0; $('#add').click(function () { var addDate = $('[data-member="AddedDate"]').val(); var Name = $('[data-member="Name"]').val(); supplierPrice = $('[data-member="SupplierPrice"]').val(); costPrice = $('[data-member="CostPrice"]').val(); SellingPrice = $('[data-member="SellingPrice"]').val(); qty = $('[data-member="Quantity"]').val(); itemid = 0; alldata = { 'ItemId': itemid, 'Quantity': qty, 'SupplierPrice': SellingPrice, 'CostPrice': costPrice, 'SellingPrice': SellingPrice }; itemlist.push(alldata); $('#tableBody').append( '<tr><td>' + Name + '</td><td>' + qty + '</td><td>' + supplierPrice + '</td><td>' + costPrice + '</td><td>' + SellingPrice + '</td>' + '<td><button class="btn btn-primary" id=" title="Edit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></button></td>' + +'</tr>'); }); $('#Save').on('click', function () { //e.preventDefault(); var serial = $('[data-member="SerialNo"]').val(); var challan = $('[data-member="ChallanNo"]').val(); var date = $('[data-member="AddedDate"]').val(); //var Detailss =JSON.stringify(itemlist); alldata = { SerialNo: serial, ChallanNo: challan, AddedDate: date }; var ur = '@Url.Action("ItemReceiveDetails", "Item")'; //var ur = '/Item/ItemReceiveDetails'; var Ddata = JSON.stringify(alldata); $.ajax({ url: ur, type: 'POST', data: { receive: { SerialNo: 'serial', ChallanNo: 'challan', AddedDate: '' }, Details: itemlist }, datatype: 'Josn', ContentType: 'application/json;utf-8', success: function (data) { var d = data; }, error: function (er) { var e = er; } }); }); }) </script>
Моя модель корреляции
public class ItemReceiveDetailsViewModel { public long ReceiveDetailsID { get; set; } public long ReceiveId { get; set; } public int ItemId { get; set; } public int Quantity { get; set; } public decimal SupplierPrice { get; set; } public decimal CostPrice { get; set; } public decimal SellingPrice { get; set; } } public class ItemReceiveViewModel { public long ReceiveID { get; set; } public string InvoiceNo { get; set; } public string SerialNo { get; set; } public string ChallanNo { get; set; } public string StockInOut { get; set; } public string AddedDate { get; set; } }
это мой соответствующий контроллер
[HttpPost] public JsonResult ItemReceiveDetails(ItemReceiveViewModel receive,ItemReceiveDetailsViewModel[] Details) { return Json(true, JsonRequestBehavior.AllowGet); }
Что я уже пробовал:
Я долго искал и пытался ,но так и не смог ее решить. Кроме того, насколько я знаю, это процесс, но я не знаю, почему он не работает?