开发者

why Page is not available under Razor

开发者 https://www.devze.com 2023-04-06 10:53 出处:网络
I move aspx views to razor. Some things are not worked (null r开发者_如何学运维eference) : Page.RouteData.Values[\"IdeaType\"]

I move aspx views to razor. Some things are not worked (null r开发者_如何学运维eference) :

Page.RouteData.Values["IdeaType"]
Page.User.IsInRole("Admin")

I have to change to:

ViewContext.RequestContext.RouteData.Values["IdeaType"]
ViewContext.RequestContext.HttpContext.User.IsInRole("Admin")

why? need to import something?


Razor's Page property returns a page state bag that can pass data between layout pages, content pages, and partial views.
WebForm's Page property returns your Page instance (it's inherited from the Control class).

They're not the same.

In general, WebForms properties and Razor properties are rather different.

Note that Razor pages also have a User property; you can just write User.IsInRole(...).

0

精彩评论

暂无评论...
验证码 换一张
取 消