I have a text field on my form that can contain html code and code with < > characters. I would like to store this in the database but first I want to encode it so it can be safely accepted without needing to do [allowHtml}.
Here's the code I use to send the data. Note that I just send one field at a time and the data that may or may not contain html code is in the javascript val variable:
$.ajax({
cache: false,
url: "/Admin/" + obj.table + "s/JsonUpdate",
dataType: 'json',
type: 'POST',
data: { pk: pk, rk: rk, fld: type, val: val }
})
On the server side controller I have this code:
[HttpPost]
public JsonResult JsonUpdate(string pk, string rk, string fld, string val) {
Content content = null;
try {
if (fld == "TempRowKey") {
One thing suggested was for me to use a viewModel and [AllowHTML] but if the data is encoded then why do I have to use [AllowHtml]
Here is what happened when I tried to send <x>. The data sent was:
pk=0006000&rk=0100&fld=Notes&val=%3Cx%3E
Then the server replied with:
Server Error in '/' Application
A potentially dangerous Request.Form value was detected from the client (val="<x>").