Asked by:
unable to route to action methods of navgrid in jqgrid

Question
-
User-1202579601 posted
using jqgrid navgrid unable to route to post actions of add/edit/delete of controllers in .net core 3.1. i tried on more than one
controller in the project. it looks searching for /Staff/Create.cshtml. Any changes in mvc routing conventions?
Is their a way to force the routing
giving full path in navgrid
The crud errors image-link https://imgur.com/CagYtUA
Monday, November 23, 2020 9:47 AM
All replies
-
User1312693872 posted
Hi,pmdrait
404 error means you have routed to an page which is not exist.
You can share your routing code and the related actions if it has, so we can check it.
Best Regards,
Jerry Cai
Wednesday, November 25, 2020 9:40 AM -
User-1202579601 posted
<table id="jqGrid1"></table> <div id="jqGridPager1"></div> <script src="~/js/jquery.min.js"></script> <script src="~/js/trirand/i18n/grid.locale-en.js"></script> <script src="~/js/trirand/jquery.jqGrid.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#jqGrid1").jqGrid({ url: "/Papers/GetData/", datatype: "json", mtype: "Get", colModel: [ { label: 'Id', name: 'Id', width: 75, hidden: true, key: true }, }); $("#jqGrid1").navGrid("#jqGridPager1", { edit: true, add: true, del: true, search: true, refresh: true,align: "left" }, { url: '/Papers/Edit/Id=1', editCaption: "The Edit Dialog", errorTextFormat: function (data) { return 'Error-e: ' + data.responseText } }, { url: '@Url.Action("Create", "Papers")', errorTextFormat: function (data) { return 'Error-a: ' + data.responseText }, }, { url: '/Papers/Delete', errorTextFormat: function (data) { return 'Error-d: ' + data.responseText }, } ); //controller public string Create([Bind("PaperType,Title,Venue,Event,Dop,Puburl")] Paper Paper) { string msg = "xxx"; var sid = HttpContext.Session.GetInt32("staffId"); if (sid != null) { staffid = (int)HttpContext.Session.GetInt32("staffId"); Paper.Status = false; Paper.StaffId = staffid; if (ModelState.IsValid) { _context.Add(Paper); _context.SaveChanges(); msg = "Saved Successfully"; } else { msg = "Validation data not successfull"; } return msg; } msg= "Validation data not successfull"; return msg; } [HttpPost, ActionName("Edit")] public string Edit(Paper pp) { string msg="Not updated"; Paper pu = _context.Papers.FirstOrDefault(p => p.Id == pp.Id); pu.Dop = pp.Dop; _context.Update(pu); msg = "Saved Successfully"; return msg; } [HttpPost] public string Delete(int id) { string msg = "Not deleted"; Paper pp = _context.Papers.FirstOrDefault(p => p.Id == id); if(pp!=null) { _context.Papers.Remove(pp); _context.SaveChanges(); msg = "Deleted successfully "; } return msg; } Startup.cs public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseStatusCodePages("text/html", "<h1>Status code page</h1> <h2>Status Code: {0}</h2>"); if (env.IsDevelopment()) { app.UseStatusCodePagesWithReExecute("/Error/{0}"); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseSession(); app.UseStaticFiles(); app.UseAuthentication(); app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute(name:"default",pattern: "{controller=Home}/{action=Index}"); }); }
Wednesday, November 25, 2020 11:56 AM -
User1312693872 posted
Hi,pmdrait
Try to change your endpoints to:
endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
Or the url: '/Papers/Edit/Id=1', will be 404.
Best Regards,
Jerry Cai
Thursday, November 26, 2020 2:22 AM -
User-1202579601 posted
I tried this option and error continued, so i did not include
Thursday, November 26, 2020 2:33 AM