Summernote and form submission in MVC c#

三世轮回 提交于 2019-12-03 11:46:21

I found my solution to the problem. This is how I am making the controller get the correct information:

<div class="modal-body" style="max-height: 600px">
    @using (Html.BeginForm())
    {
        @Html.ValidationSummary(true)
        <fieldset class="form-horizontal">
            <textarea name="textForLabelLanguage" id="textForLabelLanguage" />
            <button type="submit" class="btn btn-primary">Save changes</button>
            @Html.ActionLink("Cancel", "Index", null, new { @class = "btn " })
        </fieldset>
    }
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $('#textForLabelLanguage').summernote();
    });
</script>

Basically, if I use a textarea with a name instead of an input or anything else, it works!

However, and be warned, even though this solution works, I then get a error in the controller saying:

A potentially dangerous Request.Form value was detected from the client

This happens because I am allowing HTML. But this is a problem for another question!

Marlon Dias

Please, use [AllowHTML]

There's a good article on MSDN Request Validation in ASP.NET

"To disable request validation for a specific property, mark the property definition with the AllowHtml attribute:"

[AllowHtml]
public string Prop1 { get;  set; }
JRave

similar to what was posted earlier you can use the HTML helper

@HTML.TextAreaFor( m=> m.text, new {@id = "textFor*Model*"})

instead of <textarea>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!