可以使用以下方法将控制器的数据返回到Razor页面:
public IActionResult YourControllerName(Type yourProperty) { // do some work return RedirectToPage("./YourPageName", new { YourProperty = yourProperty }); }
这将导航回指定的Razor页面,并'yourProperty”值作为匿名对象的一部分一起传递给页面。您可以在接收该属性的Razor页面中使用它。
public class YourPageNameModel : PageModel { [BindProperty(SupportsGet = true)] public Type YourProperty { get; set; }
public void OnGet() { // your logic } }
这将使您能够在Razor页面上访问传递的属性值,访问方式为'@Model.YourProperty”。