HI All,
Please can anyone help using Area Routing which is not working using ASP.NET Core 3.1
HTML Code
<div class="row"><div class="col-12"> @Html.DropDownList("NationCase", (SelectList)ViewBag.NationList, "Select nation", new { onchange = "document.location.href = '/' + this.options[this.selectedIndex].value;", @class = "form-control form-control-sm col-sm-3 mb-1", @style = "float:left;" })</div></div
C#
[Area("Admin")] public class WebController : Controller { private readonly GlobalDBContext _context; public WebController(GlobalDBContextcontext) { _context = context; } public IActionResult Index() { getNationList(null); return View(); } [Route("/{id}")] public IActionResult Index(int id) { ViewBag.LocID = id; getNationList(id); return View(); } private void getNationList(int? id) { var nationList = _context.NationMeterTop.Select(s => new { Id = s.LocationId, Value = s.Nation }).OrderBy(s => s.Value).ToList(); ViewBag.NationList = new SelectList(nationList, "Id", "Value", id); } }
Startup.cs
app.UseEndpoints(endpoints => { endpoints.MapAreaControllerRoute( name: "MyAreaAdmin", areaName: "Admin", pattern: "Admin/{controller=Home}/{action}/{id?}"); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); });
I want when user select value from dropdown it should below action method
[Route("/{id}")] public IActionResult Index(int id) { ViewBag.LocID = id; getNationList(id); return View(); }
Thanks,
Shabbir