1

i getting this error when inserting a record with "<".

how to solve this error with inserting a string with "<" in it. im using entity framework. this column has a datatype of nvarchar.

thanks in advance.

tereško
  • 58,060
  • 25
  • 98
  • 150
  • 1
    This question has been wrongly marked as duplicate, as this specific to MVC Version 4, and can have different types of solutions (specific to architecture and version). – Shashank Chaturvedi Apr 01 '16 at 10:04

2 Answers2

14

You could try setting the attribute requestValidationMode="2.0" on the <httpRuntime /> element in web.config

<system.web>
...
    <httpRuntime targetFramework="4.5" requestValidationMode="2.0" />
...
</system.web>

And decorate your controller/action (choose the apropriate one) with:

[HttpPost]
[ValidateInput(false)]
public ActionResult MyMethod(string s)
{
    ....
}

Note: Always sanitize your input.

scheien
  • 2,457
  • 1
  • 19
  • 22
8

Apart from what @scheien already suggested you could check if you are setting the input (with potentialy dangerous script i.e. < character) to some model value that does not accept it. Try doing this:

[AllowHtml]
public string text{ get; set;}
Shashank Chaturvedi
  • 2,756
  • 19
  • 29