简体   繁体   中英

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. In "cs" part of my project the resources is recognized.
But in "razor" part in my "cshtml" file i get error. "The type or namespace name 'Resource' could not be found". 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. Click on Resource class (go to class definition - you need just press F12 when your cursor stays on class name). And check namespace of this class. Put this namespace in @using section. 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. Added Resource.resx file with String1 property. Build it. All I had to was calling @Resource.String1 in a view, without using @using directive or adding a namespace.

<h2>@Resource.String1</h2>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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