asp.net core 2 razor pages route with id

14.5k views Asked by At

There are two page one is Edit page and the other is Main Detail page which is combined data of some entities In edit page : after edit done and I posted the data to API as below

public async Task<IActionResult> OnPostAsync(Guid id)
    {
        ManufacturerAuthorizedPerson.Id = id;
        ManufacturerAuthorizedPerson.ManufacturerId = GetManufacturerId(id);
        if (!ModelState.IsValid)
        {
            await OnGetAsync(id);
            return Page();
        }
        HttpResponseMessage = await httpSystemApi.PutAsync("ManufacturerAuthorizedPersons", ManufacturerAuthorizedPerson);
        if (HttpResponseMessage.IsSuccessStatusCode)
        {
            return RedirectToPage("../Detail", ManufacturerAuthorizedPerson.ManufacturerId);
        }
        else
        {
            await OnGetAsync(id);
            return Page();
        }
    }

The ID in OnPostMethod(Guid id) is the value of edited entity. I am using the value and get the other one to use in route as below to get detail page.

ManufacturerAuthorizedPerson.ManufacturerId = GetManufacturerId(id);

but on the detail page the value coming from route ID that I sent from Edit pages post method like below

 return RedirectToPage("../Detail", ManufacturerAuthorizedPerson.ManufacturerId);

do not show up as route URL.Instead of ID is beeing same as I wa sent to Edit Page. Little bit confused. Need help please.

1

There are 1 answers

0
Bogdan On

Suddenly I have found simpe solution to this problem. You should type:

return RedirectToPage("../Detail", new {id = ManufacturerAuthorizedPerson.ManufacturerId});