1

I have an asp mvc application. in a view i have this snippet:

@Html.Label(admin.Mail)

The result is false because of the special caracter @. So how can i avoid this error and read exactly the label?

JonH
  • 32,732
  • 12
  • 87
  • 145
Lamloumi Afif
  • 8,941
  • 26
  • 98
  • 191

3 Answers3

2

If you want to display the email address, Use DisplayFor html helper method.

If Mail is a property of the Model passed, You can do it like this

@Html.DisplayFor(x=>x.Mail)

If Mail is a property of of a sub collection of your model, you can display it like this

@foreach (var i in Model.Contacts)
{
    <div> @Html.DisplayFor(s=>i.Mail)</div>
}
Shyju
  • 214,206
  • 104
  • 411
  • 497
1

If your question is how do you escape @ in Razor, the way to do it is @@.

Or you can try to write just the text-> something like <label>@admin.Mail</label>

EDIT

You can also give this a shot:

@Html.Display(admin.Mail)
Dimitar Dimitrov
  • 14,868
  • 8
  • 51
  • 79
1

Wrap your text with <text></text> tags, for example <text>mail@gmail.com</text>

Łukasz W.
  • 9,538
  • 5
  • 38
  • 63