how can i pass a <div>Hello World</div>
using jQuerys $.post()
function to an MVC controller like public JsonResult GetDiv(string element)
I've tried encodeURL()
on the client but I keep getting an Internal Server Error(500)...i'm basically trying to save HTML code to SQL Server. Thanks.
It's very likely that you'll need to decorate the specific property that you are attempting to pass with the [AllowHtml]
attribute as seen below on the property that you are attempting to use HTML for:
public class HtmlContent
{
[AllowHtml]
public string Content { get; set; }
}
And then simply bind the to that property within your Controller Action:
public JsonResult GetDiv(HtmlContent element)
{
// Access your element here
var html = element.Content;
// Save to the database
}
This will let .NET know that this string is expected to contain HTML content, which it may otherwise see as potentially malicious content and reject (similar to the 500 error that you are experiencing).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments