资源文件在Razor中无法访问。

8 浏览
0 Comments

资源文件在Razor中无法访问。

在我的composite c1剃须刀模板中,我尝试从Resource.resx文件中获取值。但我无法访问资源文件,显示为“当前内容中不存在名称“Resource””。我已经将资源文件添加到App_GlobalResources文件夹中。有人可以帮助我如何在我的剃须刀代码中访问资源文件吗?以下是我的代码:

@inherits RazorPageTemplate

@using System.Resources;

@functions {

public override void Configure()

{

TemplateId = new Guid("2c6536fd-af20-4d41-ae40-f6a09eb6fc74");

TemplateTitle = "InnerPage_En";

Layout = "InnerPageMasterLayOut.cshtml";

}

Thanks in advance for help

[Placeholder(Id = "content", Title = "Content", IsDefault = true)]

public XhtmlDocument Content { get; set; }

[Placeholder(Id = "bottom", Title = "Bottom")]

public XhtmlDocument Bottom { get; set; }

}

@{

var tes = Resources.Resource.Test;

}

0
0 Comments

在Razor中无法访问资源文件的问题可能是由于以下原因导致的:

1. 资源文件的访问修饰符设置为了默认的internal,而不是public。解决方法是将资源文件的访问修饰符设置为public。

解决方法如下:

// 在资源文件的设计视图中,找到Access Modifier(访问修饰符)下拉菜单
// 将其设置为public

![](https://i.stack.imgur.com/T3mZ4.png)

另外,如果在资源文件中无法更改访问修饰符的话,可以参考以下链接中的解决方法:stackoverflow.com/questions/4274311/…

0