How pass objects from one page to another on ASP.Net Core with razor pages?

后端 未结 5 1478
悲哀的现实
悲哀的现实 2020-12-15 17:59

I\'m developing a web application using Asp.net core 2.0 with razor pages. I\'m creating an object with some data and want to send that object to another page.

Actua

5条回答
  •  孤城傲影
    2020-12-15 18:41

    The key here is that you need to pass an anonymous object whose property names match the routing constraints defined in the Razor Page.

    For example, if you define an id (optional) routing constraint in the Razor Page:

    @page "{id?}"

    To redirect to that view passing a specific id, just do:

    return RedirectToPage("PageName", new { id = 3 });
    

    If you just one to redirect to the current page (but passing a specific id), just do:

    return RedirectToPage(new { id = 3 });
    

    If you just pass the number without the anonymous object it won't work.

提交回复
热议问题