【发布时间】:2020-06-30 10:34:48
【问题描述】:
在我的 ASP.NET Razor Pages 应用程序中,用户通常必须单击一个按钮并被重定向到应用程序的不同(内部)页面。为了保持代码的可维护性,我想避免使用字符串作为页面名称。有没有办法从静态属性或类名中获取页面名称?
public class SomeModel : PageModel
{
public ActionResult OnPostLogin()
{
// Don't want to use string because it's hard to maintain!
// return new RedirectResult("AnotherPage");
// The below is giving a compile error
// return new RedirectResult(nameof(_Pages_AnotherPage));
// How to get page name directly from class or property?
return new RedirectResult(AnotherPage....);
}
}
【问题讨论】:
标签: asp.net-core razor