Summernote和表单提交的MVC C# [英] Summernote and form submission in MVC c#

查看:1501
本文介绍了Summernote和表单提交的MVC C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用文本框summernote插件:
的http:// summernote.org/#/getting-started#basic-api

I am using the summernote plugin for text box: http://summernote.org/#/getting-started#basic-api

这是我一直在使用summmernote形式:

This is the form I have using summmernote:

<div class="modal-body" style="max-height: 600px">
    @using (Html.BeginForm())
    {
        @Html.ValidationSummary(true)
        <fieldset class="form-horizontal">
            <div id="textForLabelLanguage"></div>
            <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>

现在,在我的控制器,这是我的代码:

Now, In my controller, this is the code I have:

public ActionResult Create(UserInfo newInfo , [Bind(Prefix = "textForLabelLanguage")] string textForLabelLanguage)
{
    //logic here
}

现在的问题是, textForLabelLanguage 参数总是空。

Now the problem is that textForLabelLanguage param is always null.

这是因为我必须要通过 $('#textForLabelLanguage')代码(); 进入MVC时submiting的形式,但我不知道该怎么做!

This happens because I have to pass $('#textForLabelLanguage').code(); into MVC when submiting the form but I have no idea how to do that!

我如何解决我的问题?

推荐答案

我发现我的解决问题的办法。这是我想提出的控制器获取正确的信息:

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>



基本上,如果我用一个textarea使用名称,而不是输入或其他任何东西,它的作品!

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:

从客户端检测到有潜在危险的Request.Form值

这是因为我允许的HTML。但是,这是另外一个问题一个问题!

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

这篇关于Summernote和表单提交的MVC C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆