3

我有一个模型需要捕获 html。我已将 [AllowHtml] 属性添加到模型属性中,并且在调试时它可以在我的本地服务器上正常工作。

然而,一旦部署到生产环境,它在生产服务器上执行时可以正常工作(即我远程到服务器上并在那里浏览它),但在从任何其他机器执行时会失败并显示通常的“潜在危险等等等等”消息。

所以在我看来,这与验证所涉及的位置有关,或者我完全错过了这条船。

只是为了确认一下,我没有对 web.config 进行“特殊”更改。

请有人能解释我为什么会遇到这个问题。

模型

[AllowHtml]
[Display(Name = "Overview")]
public string Overview { get; set; }

控制器

//
// POST: /Product/
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult EditFeature(BackOffice.Models.ProductFeature model)
{
        if (ModelState.IsValid)
        {
            //insert the new product
        }
        //invalid model, return with errors
        return View(model);
 }

看法

@model BackOffice.Models.ProductFeature

@using (Html.BeginForm("AddFeature", "Product", null, FormMethod.Post, new { role = "form", @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    @Html.Hidden("ProductID", @Model.ProductID)

    <div class="modal fade" id="FeatureModal" tabindex="-1" role="dialog" aria-labelledby="FeatureModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Add a Feature</h4>
                </div>
                <div class="modal-body">
                    <div class='form-group'>
                        <label class='col-lg-2 control-label'>Title</label>
                        <div class="col-lg-10">
                            @Html.TextBoxFor(m => m.Title, new { @class = "form-control" })
                            @Html.ValidationMessageFor(m => m.Title)
                        </div>

                    </div>
                    <div class='form-group'>
                        <label class='col-lg-2 control-label'>Overview</label>
                        <div class="col-lg-10">
                            @Html.TextAreaFor(m => m.Description, 10, 40, new { @class = "ckeditor", id = "overview" })
                        </div>

                    </div>
                </div>
                <div class='clearfix'></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Add</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
}
4

1 回答 1

0

这里的方法名称不匹配。你有

@using (Html.BeginForm("AddFeature", "Product", null, FormMethod.Post, new { role = "form", @class = "form-horizontal" }))
{
}

但是您的操作方法被调用

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult EditFeature(BackOffice.Models.ProductFeature model)
{
}

AddFeature操作方法在哪里?

于 2015-11-03T22:23:39.543 回答