2
I’m implementing an example using ASP.NET Razor Pages and when trying to access the page Index I have the error that there is error in the request.
Error. An error occurred while Processing your request. Request ID: 0HLA7N3BM0ANB:00000001
Development Mode Swapping to Development Detailed information about the error that occurred.
Development Environment should not be enabled in Deployed Applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, Development Environment can be enabled by Setting the ASPNETCORE_ENVIRONMENT Environment variable to Development, and restarting the application.
Index.cshtml
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<h1>Contacts</h1>
<form method="post">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach (var contact in Model.Customers)
{
<tr>
<td>@contact.Id</td>
<td>@contact.Name</td>
<td>
<a asp-page="./Edit" asp-route-id="@contact.Id">edit</a>
<button type="submit" asp-page-handler="delete"
asp-route-id="@contact.Id">delete</button>
</td>
</tr>
}
</tbody>
</table>
<a asp-page="./Create">Create</a>
</form>
Index.cshtml.Cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RazorPagesContacts.Data;
using Microsoft.EntityFrameworkCore;
namespace RazorPagesContacts.Pages
{
public class IndexModel : PageModel
{
private readonly AppDbContext _db;
public IndexModel(AppDbContext db)
{
_db = db;
}
public IList<Customer> Customers { get; private set; }
public async Task OnGetAsync()
{
Customers = await _db.Customers.AsNoTracking().ToListAsync();
}
public async Task<IActionResult> OnPostDeleteAsync(int id)
{
var contact = await _db.Customers.FindAsync(id);
if(contact != null)
{
_db.Customers.Remove(contact);
await _db.SaveChangesAsync();
}
return RedirectToPage();
}
public void OnGet()
{
}
}
}
In configure you have this
if
if (env.IsDevelopment())
 {
 app.UseDeveloperExceptionPage();
 }
– novic
Do you have that if
– Pablo Tondolo de Vargas
Already debugged? when the error happens?
– novic
has two Onget? can not! IE, Onget and Ongetasync does the same thing and the error happens there, so comment Onget
– novic
Even one being Async?
– Pablo Tondolo de Vargas
Yes ... !!! even though Async and even having another subscription... Razor Pages has these inconveniences
– novic
The logic is: it has to execute only one of the methods? as the two Razor Pages does not know which to execute and ai the exception.
– novic
?Worked? ....
– novic
It worked, yeah, thanks
– Pablo Tondolo de Vargas