开发者

why Page is not available under Razor

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜