I use the TinyMCE editor in the admin panel of my site, so I decorate the model properties (the tinymce target) with [AllowHtml] , and I use Html.BeginForm () in the views. When I submit a form with HTML fields, everything works fine.
But I have a problem, if I use the Html.BeginForm overload ("action", "controller") in the same way, it skips [AllowHtml] and throw the well-known Request.form exception. I have to use [ValidateInput (false)] in the Action-Method to make it work without exception. You know why? Thanks in advance for clarifying
This is the script / Project : Asp.net Mvc 4:
Model /Ricetta.cs
.. [Required(ErrorMessage = "Corpo Articolo vuoto")] [AllowHtml] public string corpoTesto { get; set; } ..
Controller / RicetteController.cs
.. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create(RicettaViewModel modelloRicetta) { if (ModelState.IsValid) { ..
View Ricette / Create Called from another action method in the RicetteController as a view (Create, modelObject)
@model WebAPP_MVC4.Areas.Admin.Models.RicettaViewModel ... @using (Html.BeginForm("Create","Ricette",FormMethod.Post)){ @Html.AntiForgeryToken() @Html.ValidationSummary(true) .... <fieldset> <legend>Corpo Ricetta ~</legend> <div class="editor-label"> @Html.LabelFor(p=>p.ricetta.corpoTesto) </div> <div class="editor-field"> @Html.TextAreaFor(p=>p.ricetta.corpoTesto, new { @cols = 60, @rows = 20}) @Html.ValidationMessageFor(p=>p.ricetta.corpoTesto) </div> </fieldset> ..
source share