Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net core 2 razor pages route with id

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.

like image 374
S. Aziz Kazdal Avatar asked Sep 08 '17 08:09

S. Aziz Kazdal


1 Answers

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

return RedirectToPage("../Detail", new {id = ManufacturerAuthorizedPerson.ManufacturerId});
like image 57
Bogdan Avatar answered Nov 09 '22 17:11

Bogdan