John John
John John

Reputation: 1

How do I encode the user input for an <input type= "text"> in razor view?

I have the following input tag to implement an auto complete search:

 <input type="text" name="q" data-autocomplete-source="@Url.Action("QuickSearch", "User")" />

Will the user input be encoded automatically? And, if not, then how I can encode it?

Upvotes: 1

Views: 1975

Answers (2)

Matthew Abbott
Matthew Abbott

Reputation: 61589

With Razor, by default all values are html encoded, unless you either explicitly use Html.Raw, or are using a custom implementation of IHtmlString.

Upvotes: 2

user596075
user596075

Reputation:

Utilize the HtmlHelper.Encode() method to convert a value to an HTML-encoded string.

MSDN Reference for HtmlHelper.Encode()

Upvotes: 1

Related Questions