我有一个模型,要求捕获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 -->
}

最佳答案

此处的方法名称不匹配。你有

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


但是你的动作方法叫做

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


AddFeature操作方法在哪里?

关于c#-4.0 - AllowHtml属性不适用于生产,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19414661/

10-12 12:39
查看更多