简体   繁体   English

找不到类型或名称空间名称“资源”

[英]The type or namespace name 'Resource' could not be found

I have a resource.resx file where i have listed the variables in key value pair. 我有一个resource.resx文件,其中列出了键值对中的变量。 In "cs" part of my project the resources is recognized. 在我项目的“ cs”部分中,资源被识别。
But in "razor" part in my "cshtml" file i get error. 但是在我的“ cshtml”文件的“剃须刀”部分,我得到了错误。 "The type or namespace name 'Resource' could not be found". “找不到类型或名称空间名称'Resource'”。 What is the correct way of using resource in "razor" code? 在“剃刀”代码中使用资源的正确方法是什么?

@using Resource
....
...
<td>Name <a href="@Resource.Name"></a></td>

Go to your c# code. 转到您的C#代码。 Click on Resource class (go to class definition - you need just press F12 when your cursor stays on class name). 单击Resource类(转到类定义-当光标停留在类名上时,只需按F12键)。 And check namespace of this class. 并检查此类的名称空间。 Put this namespace in @using section. 将此名称空间放在@using节中。 But I recommend you to put definition of this namespace in pages by default. 但我建议您默认情况下在页面中放置此名称空间的定义。 You can read there how to do it. 您可以在此处阅读如何做。

I just created new MVC project. 我刚刚创建了新的MVC项目。 Added Resource.resx file with String1 property. 添加了具有String1属性的Resource.resx文件。 Build it. 建立它。 All I had to was calling @Resource.String1 in a view, without using @using directive or adding a namespace. 我只需要在视图中调用@Resource.String1 ,而不使用@using指令或添加名称空间。

<h2>@Resource.String1</h2>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM