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?

3

3 Answers 3

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>
}
Sign up to request clarification or add additional context in comments.

Comments

1

Wrap your text with <text></text> tags, for example <text>[email protected]</text>

Comments

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)

1 Comment

You mean @@Html.Label(admin.Mail) or @Html.Label(@admin.Mail). twice give me a fault result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.