1

I have coded the following EnumDropDownList:

<div class="form-group">
     @Html.LabelFor(model => model.SecurityClearance, htmlAttributes: new { @class = "control-label col-md-2 required-label" })
           <div class="col-md-10">
                @Html.EnumDropDownListFor(model => model.SecurityClearance, new { @class = "form-control", data_ng_model = "model.user.SecurityClearance", required = "required"})
                @Html.ValidationMessageFor(model => model.SecurityClearance, "", new { @class = "text-danger" })
           </div>
</div>

Which is populated by the following enum:

public enum SecurityClearance
{
    NONE = 0,
    INTERIM = 1,
    CONFIDENTIAL = 2,
    SECRET = 3,
    TOPSECRET = 4,
    TOPSECRETSCI = 5
}

Everything works fine, to a point. The list will populate properly, I can select a value, and that value saves to the database. The problems begin after the Save(). After every Save(), the current value in the dropdown list wipes itself. The database still has a right value, but it won't display in the view. Eventually, I added this to view:

{{model.user.SecurityClearance}}

This line of code evaluates to an integer corresponding to the index of the chosen enum. Even after the dropdown list 'wipes', the Angular expression will continue to evaluate to the proper index.

I am assuming that my problem is that the database is returning the integer after every save. This makes sense since the database is storing the index as an integer and not the word itself.

My question is: Am I correct in this assumption? And if so, how do I convert the index back to the proper word?

Will
  • 103
  • 12

0 Answers0