Reputation: 1
I have a database table called Skill used to generate my model with a field SkillIndex that is a smallint (byte) indexing into an enumerated type SkillEnum. I want to map the enumerated type values to their String counterparts with skillToString()
. When I call the index link created by the view, the item generated is not parsed. Here are the details:
PARTIAL CLASS (part of):
namespace RpgApp2.Models
{
public enum SkillEnum { Appraise, Bluff, Climb, Diplomacy, Intimidate, Jump, Perception };
[MetadataType(typeof(SkillMetaData))]
public partial class Skill
{
Utility util;
public String skillToString()
{
byte i = (byte) this.SkillIndex;
switch (i)
{
case (byte)SkillEnum.Appraise: return "Appraise";
case (byte)SkillEnum.Bluff: return "Bluff";
case (byte)SkillEnum.Diplomacy: return "Diplomacy";
case (byte)SkillEnum.Climb: return "Climb";
case (byte)SkillEnum.Intimidate: return "Intimidate";
case (byte)SkillEnum.Jump: return "Jump";
case (byte)SkillEnum.Perception: return "Perception";
case (byte)SkillEnum.Ride: return "Ride";
case (byte)SkillEnum.Spellcraft: return "Spellcraft";
case (byte)SkillEnum.Survival: return "Survival";
default: return "No matching skill for " + (int)i;
}
VIEW source code (Index.cshtml, partial):
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.CharacterIndex)
</td>
<td>
<% item.SkillToString(); %>
</td>
<td>
@Html.DisplayFor(modelItem => item.Ranks)
</td>
OUTPUT SOURCE (ie view source of page generated in Internet Explorer:
<tr>
<td>
1
</td>
<td>
<% item.SkillToString(); %>
</td>
<td>
1
</td>
<td>
3
</td>
The <% item.SkillToString(); %>
renders as itself and appears blank in the web page, whereas I want "Diplomacy" to appear for the value of 3.
What do I need to get the method skillToString()
method called on the current item (i.e., a Skill)?
Upvotes: 0
Views: 100
Reputation: 3502
Since you are using Razor view engine, you can use:
@item.SkillToString()
Upvotes: 1