I'm using TinyMCE editor on admin panel of my site, so i decorate the model properties (target of tinymce) with [AllowHtml] and i use Html.BeginForm() in views. When i submit form with HTML fields all work fine.
But i have a problem if i use the overload Html.BeginForm("action","controller") in the same way, it skips the [AllowHtml] and throw the well-know Request.form exception.
I'm forced to use [ValidateInput(false)] on Action-Method to make it work without exception.
Do you know why? Thanks in advance for the clarification,
This is the scenario / 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 RicetteController as 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>
..
Best Answer
I made quick test and everything works perfectly there is no difference in behavior between Html.BeginForm() and Html.BeginForm("action","controller"). Maybe the reason of this issue is in the source code which you didn't show us.
Below my code(works):
VieModel:
Controller:
View: