为什么我的 MVC razor 视图不想实例化 ResourceManager
我在 MVC 3 视图上编写此代码:
<table>
<tr>
<th>@SecondIndexStrings.Activity_ActivityName</th>
<th>@SecondIndexStrings.Activity_DateStarted</th>
<th>@SecondIndexStrings.Activity_ProficiencyLevel</th>
</tr>
@foreach (var activity in Model.Activities)
{
<tr>
<td>@activity.ActivityName</td>
<td>@activity.DateStarted.ToShortDateString()</td>
<td>@new ResourceManager(typeof(IndexStrings)).GetString(activity.ProficiencyLevel.ToString())</td>
</tr>
}
</table>
由于某种原因,带有“@new ResourceManager...”的行未被识别为有效,并且每当我运行它时都会出现编译错误。
如果我只写@ResourceManager,文本会变成蓝色,表明它被识别为有效的类,对于 IndexStrings 资源也是如此,但是,从整体来看,它似乎不知道这些应该是类。
我做错了什么?
谢谢。
I'm writing this code on an MVC 3 view:
<table>
<tr>
<th>@SecondIndexStrings.Activity_ActivityName</th>
<th>@SecondIndexStrings.Activity_DateStarted</th>
<th>@SecondIndexStrings.Activity_ProficiencyLevel</th>
</tr>
@foreach (var activity in Model.Activities)
{
<tr>
<td>@activity.ActivityName</td>
<td>@activity.DateStarted.ToShortDateString()</td>
<td>@new ResourceManager(typeof(IndexStrings)).GetString(activity.ProficiencyLevel.ToString())</td>
</tr>
}
</table>
For some reason the line with "@new ResourceManager..." is not recognized as valid and it gives me a Compilation Error whenever I run it.
If I only write @ResourceManager the text turns blue indicating that is recognized as a valid class, the same for the IndexStrings resource but, with the whole thing it seems that it doesn't know that those are supposed to be classes.
What am I doing wrong?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于存在空格,您必须使用括号来帮助它查看表达式的开始/结束位置:
您可能还需要考虑添加一个辅助方法,也许作为
HtmlHelper
上的扩展方法,因此你可以使用类似:或类似的东西,它可能看起来像:
Because of the white-space, you must use parenthesis to help it see where your expression starts/ends:
You might also want to consider adding a helper method, perhaps as an extension-method on
HtmlHelper
, so you can use something like:or similar, which might look something like: