Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Just starting out with a Razor page application using Core 2.2. An Edit page in one folder (Projects/Edit/x) includes a table of Searchfields. The Searchfield table has an edit link to /Searchfields/Edit/x folder in the cshtml file. The link works fine to get to the Searchfields Edit page. A link on the Searchfield/Edit cshtml page back to the Projects/Edit page (Back to Projects) also works fine. The problem is in the OnPostAsync task I want to save changes and return to the Projects/Edit page. The code is:
C#
public async Task<iactionresult> OnPostAsync()
{
   if (!ModelState.IsValid)
   {
      return Page();
   }

   _context.Attach(SearchField).State = EntityState.Modified;

   try
   {
      await _context.SaveChangesAsync();
   }
   
   catch (DbUpdateConcurrencyException)
   {
      if (!SearchFieldExists(SearchField.Id))
      {
         return NotFound();
      }
      else
      {
         throw;
      }
   }

   return RedirectToPage("/Projects/Edit/3");
}


What I have tried:

I have tried RedirectToPage, RedirecToRoute, as well as other variation of RedirectToRoute. By the way, the SaveChangesAsync works without error.

I get exception No page named '/Projects/Edit/3' matches the supplied values. Yet the link on the cshtml page is the same, and works fine. Thanks for any help you can provide.

I have worked through several Microsoft tutorials, but they seem to always return to a page within the same folder. Thanks for any help you can provide.
Posted
Updated 9-Aug-19 8:24am
v2

1 solution

I suspect you'll need to pass the ID in the route values, rather than as part of the page name:
C#
return RedirectToPage("/Projects/Edit", new { id = 3 });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900