I have site - user choose option from dropdown, depends oh his select site must to be generated. I use JS and blazor. I have 404 error. I tried to adapted this way: Populate DropDownList from another DropDownList
View:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@model IEnumerable<Article>
@section Scripts{
<script>
function load() {
var e = document.getElementById('titles');
var id = e.options[e.selectedIndex].value;
var Id = parseInt(id);
//C: \Users\patryk\source\repos\Blog\Controllers\Dashboard\EditPartialViewController.cs
alert(Id);
$('#container').load("/Dashboard/EditPartialViewController/_tableSeeder?id="+Id);
}
</script>
}
<h1>Edit</h1>
<form id="id_select" >
<label for="article">Choose an article to edit:</label>
<select id="titles" onchange="load()">
@foreach (var x in Model)
{
<option value=@x.Id>@x.Title</option>
}
</select>
<br><br>
There is my partialView:
@model List<Article>
@foreach (var item in Model)
{
<option value="@item.Id">
@item.Title
</option>
}
Controller for partial view:
namespace Blog.Controllers.Dashboard
{
public class EditPartialViewController : Controller
{
private ApplicationDbContext context;
public EditPartialViewController(ApplicationDbContext _context)
{
context = _context;
}
public IActionResult _tableSeeder(int id)
{
List<Article> model = context.Articles.Where(x => x.Id == id).ToList();//list with only one element
return PartialView(model);
}
}
}
WebBrowser gives me 2 errors: GEThttps://localhost:44336/Dashboard/EditPartialViewController/_tableSeeder?id=14 [HTTP/2 404 Not Found 7ms]
and second one: XML error - main element not found (or sth like that)
EDIT: my routing:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
endpoints.MapControllerRoute(
name: "Dashboard",
pattern: "{controller=Dashboard}/{action=Dashboard}");
endpoints.MapRazorPages();
//added for block registration
endpoints.MapGet("/Identity/Account/Register", context => Task.Factory.StartNew(() => context.Response.Redirect("/Identity/Account/Login", true, true)));
endpoints.MapPost("/Identity/Account/Register", context => Task.Factory.StartNew(() => context.Response.Redirect("/Identity/Account/Login", true, true)));
});