Search code examples
htmlrazor

" [ " doesn't show from @Html.DisplayText( " [ " ) , web page doesn't reflect this html code


Given this html code:

@Html.TextBoxFor(x => x.CountryName, new  { placeholder = "Country", @class = "input-medium", customerui = "Country" }) 
@Html.DisplayText( " [ " )                     
@Html.DisplayTextFor(x => x.CountryName )      
@Html.DisplayText( " ] " )                     
@Html.DisplayTextFor(x => x.CountryFootnote)  

The expectation is that the following would be shown:

  • input textbox [ VC ] Saint Vincent and The Grenadines

But instead the " [ " and " ] " are missing?


 page shown from above code



Solution

  • I did search last night and did not find @Html.DisplayText will not actually display text Which explains my posting this question.

    The helpful answer is:

    The DisplayText is synonomous for Model.PropertyName.. so Model.PropertyName = @Html.DisplayText('PropertyName')

    So if ' [ ' and ' ] ' are not attributes of your model and you are just trying to output raw text then just replace the 'DisplayText' statements with the raw text:

                <text> [ </text>
                @Html.DisplayTextFor(x => x.CountryName )
                <text> ] </text>