Ser*_*ero 2 c# localization asp.net-mvc-3
我在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>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,带有"@new ResourceManager ..."的行无法识别为有效,并且每次运行它时都会给出编译错误.
如果我只编写@ResourceManager,则文本变为蓝色表示被识别为有效类,对于IndexStrings资源也是如此,但是,整个事情似乎并不知道那些应该是类.
我究竟做错了什么?
谢谢.
由于空格,您必须使用括号来帮助它查看表达式的开始/结束位置:
@(new ResourceManager(typeof(IndexStrings)).GetString(activity.ProficiencyLevel.ToString()))
Run Code Online (Sandbox Code Playgroud)
您可能还想考虑添加辅助方法,可能作为扩展方法HtmlHelper,因此您可以使用以下内容:
@Html.Resource<IndexStrings>(activity.ProficiencyLevel)
Run Code Online (Sandbox Code Playgroud)
或类似的,可能看起来像:
public static string Resource<T>(this HtmlHelper html, object key) {
return new ResourceManager(typeof(T)).GetString(key.ToString());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1086 次 |
| 最近记录: |