我将 aspx View 移动到 razor。有些事情不起作用(空引用):
Page.RouteData.Values["IdeaType"]
Page.User.IsInRole("Admin")
我必须更改为:
ViewContext.RequestContext.RouteData.Values["IdeaType"]
ViewContext.RequestContext.HttpContext.User.IsInRole("Admin")
为什么?
需要导入一些东西吗?
最佳答案
Razor 的 Page
属性返回一个页面状态包,可以在布局页面、内容页面和部分 View 之间传递数据。
WebForm 的 Page
属性返回您的 Page
实例(它继承自 Control
类)。
它们不一样。
一般来说,WebForms 属性和 Razor 属性有很大不同。
请注意,Razor 页面还有一个 User
属性;你可以只写User.IsInRole(...)
。
关于asp.net-mvc-3 - 为什么页面在 Razor 下不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7474558/