加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 我可以在Razor视图中访问C#枚举吗?

发布时间:2020-12-16 03:27:59 所属栏目:asp.Net 来源:网络整理
导读:我有以下内容: namespace Storage.Constants.References { public enum RoleType { Guest = 1,User = 2,Admin = 3,Super = 4 }} 在我的web.config中,我添加了: add namespace="Storage.Constants.References" / 但是在我看来,我仍然没有获得RoleType的任何
我有以下内容:

namespace Storage.Constants.References {
    public enum RoleType {
        Guest = 1,User = 2,Admin = 3,Super = 4
    }
}

在我的web.config中,我添加了:

<add namespace="Storage.Constants.References" />

但是在我看来,我仍然没有获得RoleType的任何intellisense,它似乎不知道它是什么:

@model WebUx.ViewModels.BaseViewModel
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
@section status {

    @if (Model.Role >= RoleType.Admin)
    {

但是,如果我将其更改为:

@if (Model.Role >= Storage.Constants.References.RoleType.Admin)

如果没有我指定“Storage.Constants.References”,它应该不起作用吗?

解决方法

您是否尝试将namspace添加到剃刀视图中?

@using Storage.Constants.References

此外,如果要在Web配置文件中添加它,请确保添加到Views文件夹中的webconfig,而不是根级web配置

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读