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.
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: