Asp.net mvc Html.BeginForm()工作正常,Html.BeginForm(“操作”、“控制器”)忽略[AllowHtmlAttribute]

Asp.net mvc Html.BeginForm()工作正常,Html.BeginForm(“操作”、“控制器”)忽略[AllowHtmlAttribute],asp.net-mvc,asp.net-mvc-4,tinymce,Asp.net Mvc,Asp.net Mvc 4,Tinymce,我在我网站的管理面板上使用,所以我用[allowtml]装饰模型属性(tinymce的目标),并在视图中使用Html.BeginForm()。当我提交带有HTML字段的表单时,一切都很好 但是如果我以同样的方式使用重载Html.BeginForm(“action”、“controller”),我会遇到一个问题,它会跳过[AllowHtml]并抛出众所周知的Request.form异常。 我被迫在Action方法上使用[ValidateInput(false)]使其毫无例外地工作。 你知道为什么吗

我在我网站的管理面板上使用,所以我用[allowtml]装饰模型属性(tinymce的目标),并在视图中使用Html.BeginForm()。当我提交带有HTML字段的表单时,一切都很好

但是如果我以同样的方式使用重载Html.BeginForm(“action”、“controller”),我会遇到一个问题,它会跳过[AllowHtml]并抛出众所周知的Request.form异常。 我被迫在Action方法上使用[ValidateInput(false)]使其毫无例外地工作。 你知道为什么吗?提前感谢您的澄清

这是场景/项目:Asp.net Mvc 4:

型号/Ricetta.cs

..
[Required(ErrorMessage = "Corpo Articolo vuoto")]
[AllowHtml]
public string corpoTesto { get; set; }
..
..
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(RicettaViewModel modelloRicetta)
    {
        if (ModelState.IsValid) {
..
控制器/RicetteController.cs

..
[Required(ErrorMessage = "Corpo Articolo vuoto")]
[AllowHtml]
public string corpoTesto { get; set; }
..
..
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(RicettaViewModel modelloRicetta)
    {
        if (ModelState.IsValid) {
..
查看Ricette/Create作为视图从RicetteController中的另一个操作方法调用(“Create”,modelObject)

@model WebAPP\u MVC4.Areas.Admin.Models.RicettaViewModel
...
@使用(Html.BeginForm(“Create”、“Ricette”、FormMethod.Post)){
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
....
科波里塞塔酒店~
@LabelFor(p=>p.ricetta.corpoTesto)
@TextAreaFor(p=>p.ricetta.corpoTesto,new{@cols=60,@rows=20})
@Html.ValidationMessageFor(p=>p.ricetta.corpoTesto)
..

我做了快速测试,一切正常。Html.BeginForm()和Html.BeginForm(“操作”、“控制器”)之间的行为没有区别。可能问题的原因在于您没有向我们展示的源代码。

下面是我的代码(作品):
VIE模型:

public class PostViewModel
{
    [AllowHtml]
    [Required]
    public string Content { get; set; } 
}
控制器:

public ActionResult Index()
{
    return View("Create", new PostViewModel());
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(PostViewModel model)
{
    if (ModelState.IsValid)
    {
        return Index();
    }
    return View(model);
}
视图:

@model SendHTmlTpControler.Models.PostViewModel
tinymce.init({
选择器:“文本区域”,
工具栏:“插入文件撤消重做|样式选择|粗体斜体|对齐左对齐中心对齐右对齐对齐对齐|粗体numlist outdent缩进|链接图像”
});
创造
@使用(Html.BeginForm(“Create”、“Home”、FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@LabelFor(model=>model.Content)
@Html.TextAreaFor(model=>model.Content,new{@cols=60,@rows=20})
@Html.ValidationMessageFor(model=>model.Content)

}
谢谢你的回答。我不知道为什么,但我已经有好几个小时的错误了。现在一切正常了,你认为是firefox缓存问题吗?我将TinyMCE的设置从“selector:“textarea”更改为“exact:“id”。因此在过去版本的view all text area字段中(其中许多字段在模型上没有[Allowhtml])生成请求。表单错误(对)。当我在模型上用[allowhtml]设置tinymce.init仅用于textarea字段后,错误会继续弹出,直到电脑重新启动(为什么?)。无论如何,所有操作都按预期进行,因此很难说是什么问题,如果缓存或某些js错误,那么您应该使用开发人员工具(例如)如果您认为该页面可以工作,但无法在其他浏览器中进行检查。在Visual Studio重新启动后解决问题时,我的生活中只有2-3种情况。问题是来自“Ricetta model”及其父级“Articolo”的TPT层次结构。如果您定义了两个不同的元属性类,则验证属性不会共享(一个元类带有“与”Ricetta共享的Articolo字段,一个元类只有Ricetta字段)。我知道,我是个白痴://P.s.上次尝试成功了,因为我忘记了[ValidationInput(false)],没有jquery bug。这是我第一个使用asp.net的大型web应用程序,所以我不是很好。谢谢你的时间亚当:)