سلام
در کد زیر میخواهم اطلاعات را ارسال کنم برای Create ولی میره سراغ اکشن Get به جای Post
//------------< jQuery - script > ------------ $(document).ready(function () { $("#upload").click(function (evt) { var data = new FormData(); var files = $("#STicket_Files").get(0).files; var isvalid = $("#Form_Id").valid(); // Tells whether the form is valid if (isvalid === false) return false; else { data.append("STicket_Files", files[0]); data.append("STicket_Text", $("#STicket_Text").val()); data.append("Ticket_Id", $("#Ticket_Id").val()); $.ajax({ type: "POST", url: "/TicketDetails/Create", contentType: false, processData: false, data: { viewModel:data }, success: function (data) { swal({ type: 'success', title: "بارگداری فایل ", text: "فایل با موفقیت بارگذاری شد", showConfirmButton: true, confirmButtonText: "تائید", }) }, error: function (e) { swal("خطا", "خطلا در ارسال اطلاعات دوباره سعی کنید", "error"); } }); } }); });
Controller
[HttpGet] // GET: TicketDetails/Create public async Task<IActionResult>Create(int id) { var ticketMaster = await _genericRepository_TicketMaster.GetByIdIncludesAsync(m => m.Ticket_Id == id, "TicketMaster"); ViewData["Ticket_Id"] = ticketMaster.Ticket_Id; ViewData["Ticket_Title"] = ticketMaster.Ticket_Title; return View(); } // POST: TicketDetails/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] public async Task<IActionResult> Create(TicketDetailsViewModel viewModel) { //if (ModelState.IsValid) //{ // _genericRepository.Add(ticketDetails); // await _genericRepository.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); //} //ViewData["Ticket_Id"] = new SelectList(await _genericRepository_TicketMaster.GetAllAsync(), "Ticket_Id", "Ticket_CreateDate", ticketDetails.Ticket_Id); return View(viewModel); }
صفت AtiForgery را از Post بردارید یا در Ajax باید Token را قرار دهید
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)