C # returns an HTML string

0

Good,

I use the following code to convert a numeric value according to the user's culture:

value="@(Model.KnowAcquisition.Cost.HasValue ? Model.KnowAcquisition.Cost.Value.ToString("n2", CultureInfo.CurrentCulture).ToString() : string.Empty)" />

However, C # transforms into this:

<input type="text" class="famo-input famo-text-10" name="cost" value="1&nbsp;000,25">

My problem is that it should be a space instead of &nbsp . I have already tested with normal strings and shows the space, only when I use ToString () with an associated culture does it show &nbsp .

How can I change?

    
asked by anonymous 10.10.2017 / 18:45

2 answers

1

I already found a solution, had to do a replace in C #:

@{ 
    string cost = (Model.KnowAcquisition.Cost.HasValue ? Model.KnowAcquisition.Cost.Value.ToString("n2", CultureInfo.CurrentCulture) : string.Empty).Replace("\u00A0", " ");
}

<input type="text" class="famo-input famo-text-10" name="cost" value="@cost" />

The NumberFormatInfo.NumberGroupSeparator appears to be the same as Non-Breaking Space.

    
10.10.2017 / 21:38
1

You can use Html.Raw () for that there is no HTML encoding in the string.

It would look like this:

<input type="text" class="famo-input famo-text-10" name="cost" value="@Html.Raw(Model.KnowAcquisition.Cost.HasValue ? Model.KnowAcquisition.Cost.Value.ToString("n2", CultureInfo.CurrentCulture).ToString() : string.Empty)" />

Also try, as follows (using HttpUtility.HtmlDecode () ), if the string is already encoded for HTML:

<input type="text" class="famo-input famo-text-10" name="cost" value="@Html.Raw(Model.KnowAcquisition.Cost.HasValue ? HttpUtility.HtmlDecode(Model.KnowAcquisition.Cost.Value.ToString("n2", CultureInfo.CurrentCulture).ToString()) : string.Empty)" />
    
10.10.2017 / 18:48