good morning, I have the following problem to solve.
I show you the context
I have a project with .net core 3.1 and mvc in which by means of scafolding I connect to the database, the models, controllers and views were created, execute the application and effectively everything should be running dome. but actually what I want is to do a crud with jquery and ajax, and that's when I already have a problem, for this I go on to show the code I have.
mi Controller
- public ComAnticipoesController(ChilyContext context)
- {
- _context = context;
- }
-
-
- public async Task<IActionResult> Index()
- {
- return View(await _context.ComAnticipos.ToListAsync());
- }
a View Index
In the _Layout.cshtml, I made the following change
- <li class="nav-item">
- @*<a id="anticipo" class="nav-link text-dark" asp-area="" asp-controller="ComAnticipoes" asp-action="Index">Anticipos</a>*@
- <a id="anticipo" class="nav-link text-dark" asp-area="" >Anticipos</a>
- </li>
and add at the bottom this script
- <script>
- $("#anticipo").click(function () {
-
- CargarDatos();
- });
- function CargarDatos() {
- $.ajax({
- type: "Get",
-
- url: "@Url.Content("~/ComAnticipoes/Index")",
- cache: false,
- success: function (dataHtml) {
- $("~/#example").html(dataHtml);
- }
- });
- }
-
- </script>
I tried some other options in the url thinking that it might not find the Index sheet or view but I have not managed to load my data.
Please help me to solve my problem and see what my mistake was
Thanks you
Roberto