Ошибка javascript в ASP.NET ядро 3.1
модель представления :
public enum YearsType { [Display(Name = "سال جاری")] Currentyear = 1, [Display(Name = "سالهای گذشته")] Pastyears = 2, } public class InventoryAnalysisReportViewModel { [Display(Name = "وضعیت")] public YearsType YearType { get; set; } [Display(Name = "وضعیت")] public string YearTypeName { get { switch (YearType) { case YearsType.Currentyear: return "سال جاری"; case YearsType.Pastyears: default: return "سالهای گذشته "; } } } public int CarId { get; set; } [Display(Name = "خودرو")] public string CarTitle { get; set; } [Display(Name = "بین مقاطع")] public int SectionsQty { get; set; } [Display(Name = "تحویل موقت")] public int ProvisionalDeliveryQty { get; set; } [Display(Name = "کل تعهدات باقیمانده")] public int RemailQty { get; set; } [Display(Name = "تکمیل وجه شده")] public int PayOffQty { get; set; } [Display(Name = "تکمیل وجه نشده")] public int DebtQty { get; set; } [Display(Name = "تخصیص کل")] public int TotalAllocatedQty { get; set; } [Display(Name = "موجودی پارکینگ بم")] public int? ParkingInventoryQty { get; set; } [Display(Name = "مجوز حمل")] public int? Qty { get; set; } [Display(Name = "موجودی تجاری شده")] public int InventoryQty { get; set; } public long ProductionVehicleInventoryId { get; set; } [Display(Name = "کل موجودی")] public int TotalInventory { get; set; } [Display(Name = "مجموع")] public int TotalDeatails { get; set; } [Display(Name = "کسری/مازاد (حال حاضر)")] public int ExcessNow { get; set; } [Required(ErrorMessage = "{0} الزامی است.")] public DateTime RegDate { get; set; } } }
вид:
@model IEnumerable<InventoryAnalysisReportViewModel> @{ ViewData["Title"] = "آنالیز موجودی/درخواست"; } <div class="card text-white"> <div class="card-body"> <h5 class="card-title">@($"{ViewData["Title"]} {ViewData["Range"]}")</h5> <form method="post" asp-controller="InventoryAnalysisReports" asp-action="SpecificDate"> <div class="form-group"> <div class="form-inline"> <label for="SelectedDate">تاریخ گزارش :</label> <input id="SelectedDate" name="SelectedDate" class="form-control" autocomplete="off" required /> <label class="col-sm-1"> </label> <input type="submit" class="btn btn-light mb-2 " value="جستجو"> </div> </div> </form> </div> </div> @section Scripts { <script> $(document).ready(function () { $('#SelectedDate').val('@ViewData["Yesterday"].ToString()').persianDatepicker(); }); </script> } <hr /> <h5>آنالیز موجودی/درخواست | @ViewData["Yesterday"].ToString()</h5> <br /> <table class="table text-center"> <thead> <tr class="text-right"> <th> </th> <th> @Html.DisplayNameFor(model => model.CarTitle) </th> <th> @Html.DisplayNameFor(model => model.ProvisionalDeliveryQty) </th> <th> @Html.DisplayNameFor(model => model.SectionsQty) </th> <th> @Html.DisplayNameFor(model => model.ParkingInventoryQty) </th> <th> @Html.DisplayNameFor(model => model.InventoryQty) </th> <th> @Html.DisplayNameFor(model => model.TotalInventory) </th> <th> @Html.DisplayNameFor(model => model.RemailQty) </th> <th> @Html.DisplayNameFor(model => model.PayOffQty) </th> <th> @Html.DisplayNameFor(model => model.DebtQty) </th> <th> @Html.DisplayNameFor(model => model.ExcessNow) </th> <th> @Html.DisplayNameFor(model => model.TotalAllocatedQty) </th> <th> @Html.DisplayNameFor(model => model.Qty) </th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> <a href="#" data-id="@item.CarId" name="sales-details"> </a> </td> <td> @Html.DisplayFor(modelItem => item.CarTitle) </td> <td> @Html.DisplayFor(modelItem => item.ProvisionalDeliveryQty) </td> <td> @Html.DisplayFor(modelItem => item.SectionsQty) </td> <td> @Html.DisplayFor(modelItem => item.ParkingInventoryQty) </td> <td> @Html.DisplayFor(modelItem => item.InventoryQty) </td> <td> @Html.DisplayFor(modelItem => item.TotalInventory) </td> <td> @Html.DisplayFor(modelItem => item.RemailQty) </td> <td> @Html.DisplayFor(modelItem => item.PayOffQty) </td> <td> @Html.DisplayFor(modelItem => item.DebtQty) </td> <td> @Html.DisplayFor(modelItem => item.ExcessNow) </td> <td> @Html.DisplayFor(modelItem => item.TotalAllocatedQty) </td> <td> @Html.DisplayFor(modelItem => item.Qty) </td> </tr> <tr> <td colspan="13"> <div id="div-@item.CarId"></div> </td> </tr> } </tbody> </table>
сценарий Java:
$('a[name="sales-details"]').click(function (event) { event.preventDefault(); var carId = $(event.currentTarget).data('id'), selectedDate = $('#SelectedDate').val(); if ($('#icon-' + carId).hasClass('fa-plus-square')) { showRows(carId, selectedDate); } else { hideRows(carId); } }); function showRows(carId, selectedDate) { $.ajax({ type: 'POST', url: '/InventoryAnalysisReports/DeatailsAnalysis', data: { carId: carId, selectedDate: selectedDate }, dataType: 'json', success: function (result) { if (result.length > 0) { var template = '<table class="inventoryAnalysisReport">' + '<colgroup>' + '<col style="width:auto;" />' + '<col style="width:auto;" />' + '<col style="width:auto;" />' + '<col style="width:auto;" />' + '<col style="width:auto;" />' + '</colgroup>' + '<thead>' + '<tr>' + '<th></th>' + '<th>بین مقاطع</th>' + '<th>تحویل موقت</th>' + '<th>پارکینگ بم</th>' + '<th>تجاری شده</th>' + '<th>جمع کل</th>' + '</tr>' + '</thead>' + '<tbody>'; for (var i = 0; i < result.length; i++) { var item = result[i]; typeName = (item.yearType == 1) ? 'سال جاری' : 'سالهای گذشته'; template += '<tr>' + '<td>' + typeName + '</td>' + '<td>' + item.sectionsQty + '</td>' + '<td>' + item.provisionalDeliveryQty + '</td>' + '<td>' + item.parkingInventoryQty + '</td>' + '<td>' + item.inventoryQty + '</td>' + '<td>' + item.totalDeatails + '</td>' + '</td>' + '</tr>'; } template += '</tbody>' + '</table>'; } $('#div-' + carId).append(template); $('#icon-' + carId).removeClass('fa-plus-square').addClass('fa-minus-square'); }, error(ex) { debugger; } }); } function hideRows(carId) { $('#div-' + carId).children().remove(); $('#icon-' + carId).removeClass('fa-minus-square').addClass('fa-plus-square'); }
контроллер:
public class InventoryAnalysisReportsController : PersianController { public InventoryAnalysisReportsController(KMCDashboardDbContext context) : base(context) { } // GET: InventoryAnalysisReportViewModels public async Task<IActionResult> Index() { var yesterday = DateTime.Today.AddDays(-1); ViewData["Yesterday"] = $"{Calendar.GetYear(yesterday)}/{Calendar.GetMonth(yesterday)}/{Calendar.GetDayOfMonth(yesterday)}"; var model = await InventoryAnalysisReportAsync(yesterday); return View(model); } [HttpPost] public async Task<IActionResult> SpecificDate(string selectedDate) { ViewData["Yesterday"] = selectedDate; DateTime selectedDay = PersianToGregorian(selectedDate, out _); var model = await InventoryAnalysisReportAsync(selectedDay); return View("Index", model); } public async Task<IActionResult> History(string historyDate) { SqlConnection connection = null; SqlCommand command = null; var model = new List<InventoryAnalysisReportViewModel>(); try { connection = DbContext.Database.GetDbConnection() as SqlConnection; command = new SqlCommand("dbo.InventoryAnalysisReportPerDay") { CommandType = CommandType.StoredProcedure, Connection = connection }; command.Parameters.Add(new SqlParameter("@HistoryDate", historyDate)); if (connection.State != ConnectionState.Open) await connection.OpenAsync(); using var reader = await command.ExecuteReaderAsync(); while (await reader.ReadAsync()) { model.Add(new InventoryAnalysisReportViewModel { CarId = reader.GetInt32(reader.GetOrdinal("CarID")), CarTitle = reader.GetString(reader.GetOrdinal("CarTitle")), ProvisionalDeliveryQty = reader.GetInt32(reader.GetOrdinal("ProvisionalDeliveryQty")), SectionsQty = reader.GetInt32(reader.GetOrdinal("SectionsQty")), ParkingInventoryQty = reader.GetInt32(reader.GetOrdinal("ParkingInventoryQty")), RemailQty = reader.GetInt32(reader.GetOrdinal("RemailQty")), PayOffQty = reader.GetInt32(reader.GetOrdinal("PayOffQty")), DebtQty = reader.GetInt32(reader.GetOrdinal("DebtQty")), //InventoryQty = reader.GetInt32(reader.GetOrdinal("InventoryQty")), TotalAllocatedQty = reader.GetInt32(reader.GetOrdinal("TotalAllocatedQty")), //TotalInventory = reader.GetInt32(reader.GetOrdinal("TotalInventory")), //ExcessNow = reader.GetInt32(reader.GetOrdinal("ExcessNow")), Qty = reader.GetInt32(reader.GetOrdinal("Qty")) }); } } catch (Exception ex) { throw ex; } finally { if (command != null) { command.Dispose(); } if (connection.State != ConnectionState.Closed) { connection.Close(); connection.Dispose(); } } return Json(model); } [HttpPost] public async Task<IActionResult> DeatailsAnalysis(int carId, string selectedDate) { DateTime selectedDay = PersianToGregorian(selectedDate, out int selectedPersianYear); SqlConnection connection = null; SqlCommand command = null; var model = new List<InventoryAnalysisReportViewModel>(); try { connection = DbContext.Database.GetDbConnection() as SqlConnection; command = new SqlCommand("dbo.DeatailsInventoryAnalysisReportPerDay") { CommandType = CommandType.StoredProcedure, Connection = connection }; command.Parameters.Add(new SqlParameter("@SelectedDay", selectedDay)); command.Parameters.Add(new SqlParameter("@CarId", carId)); if (connection.State != ConnectionState.Open) await connection.OpenAsync(); using var reader = await command.ExecuteReaderAsync(); while (await reader.ReadAsync()) { model.Add(new InventoryAnalysisReportViewModel { CarId = reader.GetInt32(reader.GetOrdinal("CarID")), CarTitle = reader.GetString(reader.GetOrdinal("CarTitle")), ProvisionalDeliveryQty = reader.GetInt32(reader.GetOrdinal("ProvisionalDeliveryQty")), SectionsQty = reader.GetInt32(reader.GetOrdinal("SectionsQty")), ParkingInventoryQty = reader.GetInt32(reader.GetOrdinal("ParkingInventoryQty")), //InventoryQty = reader.GetInt32(reader.GetOrdinal("InventoryQty")), TotalDeatails = reader.GetInt32(reader.GetOrdinal("TotalDeatails")), YearType = Convert.ToInt32(reader.GetValue(reader.GetOrdinal("CarModels"))) == selectedPersianYear ? YearsType.Currentyear : YearsType.Pastyears }); } } catch (Exception ex) { throw ex; } finally { if (command != null) { command.Dispose(); } if (connection.State != ConnectionState.Closed) { connection.Close(); connection.Dispose(); } } return Json(model); } private async Task<IEnumerable<InventoryAnalysisReportViewModel>> InventoryAnalysisReportAsync(DateTime selectedDay) { /* * ProductionVehicleInventory.SectionsQty بین مقاطع * ProductionVehicleInventory.ProvisionalDeliveryQty تحویل موقت * ProductionInventoryAnalysis.ParkingInventoryQty موجودی پارکینگ بم * SaleCommitmentSummary.RemailQty كل تعهدات * SaleCommitmentSummary.PayOffQty تكميل وجه شده * SaleCommitmentSummary.DebtQty تكميل وجه نشده * SaleTotalSale.TotalAllocatedQty تخصیص کل * ControlShippingPermit.Qty مجوز حمل * (TotalInventory - PayOffQty).ExcessNow کسری / مازاد حال حاضر * (SectionsQty + ProvisionalDeliveryQty + InventoryQty + ParkingInventoryQty).TotalInventory کل موجودی */ SqlConnection connection = null; SqlCommand command = null; var model = new List<InventoryAnalysisReportViewModel>(); try { connection = DbContext.Database.GetDbConnection() as SqlConnection; command = new SqlCommand("dbo.InventoryAnalysisReportPerDay") { CommandType = CommandType.StoredProcedure, Connection = connection }; command.Parameters.Add(new SqlParameter("@SelectedDay", selectedDay)); if (connection.State != ConnectionState.Open) await connection.OpenAsync(); using var reader = await command.ExecuteReaderAsync(); while (await reader.ReadAsync()) { model.Add(new InventoryAnalysisReportViewModel { CarId = reader.GetInt32(reader.GetOrdinal("CarID")), CarTitle = reader.GetString(reader.GetOrdinal("CarTitle")), ProvisionalDeliveryQty = reader.GetInt32(reader.GetOrdinal("ProvisionalDeliveryQty")), SectionsQty = reader.GetInt32(reader.GetOrdinal("SectionsQty")), ParkingInventoryQty = reader.GetInt32(reader.GetOrdinal("ParkingInventoryQty")), RemailQty = reader.GetInt32(reader.GetOrdinal("RemailQty")), PayOffQty = reader.GetInt32(reader.GetOrdinal("PayOffQty")), DebtQty = reader.GetInt32(reader.GetOrdinal("DebtQty")), //InventoryQty = reader.GetInt32(reader.GetOrdinal("InventoryQty")), TotalAllocatedQty = reader.GetInt32(reader.GetOrdinal("TotalAllocatedQty")), //TotalInventory = reader.GetInt32(reader.GetOrdinal("TotalInventory")), //ExcessNow = reader.GetInt32(reader.GetOrdinal("ExcessNow")), Qty = reader.GetInt32(reader.GetOrdinal("Qty")) }); } } catch (Exception ex) { throw ex; } finally { if (command != null) { command.Dispose(); } if (connection.State != ConnectionState.Closed) { connection.Close(); connection.Dispose(); } } return model; } } }
Что я уже пробовал:
When I run the program in the detail section, the door stops on the debugger and the detail is not displayed
Richard MacCutchan
Вам нужно быть гораздо более точным в том, где останавливается отладчик и почему. Там слишком много кода, чтобы кто-то мог понять, что происходит.