How to insert &nbsp in a @Html.DisplayFor(m => m.EventDetailSection.ContactAccountTel)

123 views Asked by At

Currently, I'm using the @Html.DisplayFor(m => m.EventDetailSection.ContactAccountTel), but this will output a regular number without any spaces in between like: +3194949494, I'd like to add spaces after 2 numbers and then 3. How can I achieve this, do I have to use Splice?

1

There are 1 answers

2
Tomato32 On

my friend. I think you can use Substring() or Insert() method for this.

Just set the data of property before display on View. Here is a sample. Hope to help, my friend :))

public class MyModel
    {
        public string Number { get; set; }
    }

var model = new MyModel { Number = "+3194949494" };            
model.Number = model.Number != null ? model.Number.Insert(3, " ").Insert(7, " ") : string.Empty;

<h1>@Html.DisplayFor(m => m.Number)</h1>

Or change on View

@{
    Model.Number = Model.Number != null ? Model.Number.Insert(3, " ").Insert(7, " ") : string.Empty;
    <h1>@Html.DisplayFor(m => m.Number)</h1>
}