public const string with punctuation fails to render in MVC view

public const string Foo = "I cannot see this text (i.e. only this text)"
public const string Bar = "I cannot see this either ; just this"

Result:

only this text)

I tried escaping:

public const string Foo = "I cannot see this text \\(i\\.e\\. only this text)"

same issue.

The constants are contained in a class within my ViewModel and accessed via this loop and helper function:

@functions {
    private static string GetEnumDescription(object value)
    {
        var type = typeof(FinancialsUploadViewModel.QualityOfFinancialsEnumDescriptions);
        return type.GetField(value.ToString()).GetValue(null).ToString();
    }
}

@foreach (var value in Enum.GetValues(typeof(ApplicationQualityOfFinancials.AccrualRevenueRecognitionChoices)))
{
    <div class="form-control">
    @Html.RadioButtonFor(m => m.QualityOfFinancials.AccrualRevenueRecognition, value)
    @Html.Label(GetEnumDescription(value), new { @for = value.ToString() })
    </div>
}

Note that AccrualRevenueRecognitionChoices is an Enum class that I fetch from a service (so I cannot use attributes to get the description, etc.):

    [DataMember]
    [Column("accrual_revenue_recognition")]
    public int? AccrualRevenueRecognitionId
    {
        get
        {
            return (int)this.AccrualRevenueRecognition;
        }
        set
        {
            if (value != null) AccrualRevenueRecognition = (AccrualRevenueRecognitionChoices) value;
        }
    }

    [DataMember]
    [EnumDataType(typeof(AccrualRevenueRecognitionChoices))]
    public AccrualRevenueRecognitionChoices AccrualRevenueRecognition { get; set; }

    [DataContract]
    public enum AccrualRevenueRecognitionChoices
    {
        [EnumMember]
        [Display(Name = "")]
        AccuralEvenly = 1,
        [EnumMember]
        [Display(Name = "")]
        AccrualAtInvoice = 2,
        [EnumMember]
        [Display(Name = "")]
        AccuralAtPayment = 3
    }

1 answer

  • answered 2018-03-13 21:49 Francesco B.

    F12 in your browser, select your label (or wherever you print those tests) and check the rendered HTML. You will see that your text is there fully, but the length of those labels is not enough: make them longer via CSS and you will see all the text.