Click here to Skip to main content
14,429,185 members
Rate this:
Please Sign up or sign in to vote.
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:
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 9:24am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100