1

嗨,我已将tinyMCE文本编辑器添加到我的项目中。但是现在我的表单不会提交,我也没有收到任何错误消息或任何东西。我在这里做错了什么?

我的 .cshtml 代码

@{
Layout = "~/Views/_Layout.cshtml"; //Got a link to the tinyMCE file

var con = DatabaseConnection.createConnection();
string subject = "";
string content = "";
string signed = "";
string message_error = "";
int subfolderTo = 0;
int id = 0;
bool error = false;

if(Request["btn"] == "Save entry")
{
    subject = Request["subject"];
    content = Request["content"];
    signed = Request["signed"];

    if(Request.QueryString["Chapter"] != null)
    {
        subfolderTo = Convert.ToInt32(Request.QueryString["Chapter"]);
    }

    if(subfolderTo == 0)
    {
        try
        {
            id = Subjects.Create(con, SessionHandler.WhoIsLoggedIn._id, subject, content, signed);
            Response.Redirect("~/Pages/Chapters/Read.cshtml?Chapter=" + id);
        }
        catch
        {
            error = true;
            message_error = "A monkey ran away with the text before we could save it, we are very sorry. Please try again.";
        }
    }
    else
    {
        try
        {
            id = Subjects.Create(con, SessionHandler.WhoIsLoggedIn._id, subject, content, signed, subfolderTo);
            Response.Redirect("~/Pages/Chapters/Read.cshtml?Chapter=" + id);
        }
        catch
        {
            error = true;
            message_error = "A monkey ran away with the text before we could save it, we are very sorry. Please try again.";
        }
    }
}

}


@section head{
<script type="text/javascript">
    tinymce.init({
        selector: "textarea",
        theme: "modern",
        plugins: [
            "advlist autolink lists link image charmap print preview hr anchor pagebreak",
            "searchreplace wordcount visualblocks visualchars code fullscreen",
            "insertdatetime media nonbreaking save table contextmenu directionality",
            "emoticons template paste textcolor moxiemanager"
        ],
        toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
        toolbar2: "print preview media | forecolor backcolor emoticons",
        image_advtab: true,
        templates: [
            { title: 'Test template 1', content: 'Test 1' },
            { title: 'Test template 2', content: 'Test 2' }
        ]
    });
</script>

}


<div>
<h1>
    Write new entry
</h1>
<form action="" method="post">
    <p class="Error_Message">@message_error</p>
    <table>
        <tr>
            <td>
                <p>
                    <input type="text" name="subject" placeholder="Subject" value="@subject" required="required"/>
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <p>
                    <textarea name="content" placeholder="Content" required="required"></textarea> // used to be a <input type="text" ... /> before
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <p>
                    <input type="text" name="signed" placeholder="In-time signed name" value="@signed" required="required" />
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" value="Save entry" name="btn" />
            </td>
        </tr>
    </table>
</form>
</div>
4

2 回答 2

1

如果要发布 HTML,则必须使用Request.Unvalidated()来引用 textarea 内容:

content = Request.Unvalidated("content");
于 2013-09-22T19:35:25.453 回答
0

我不知道为什么,但是在添加时

content = Request.Unvalidated("content");

和改变

<textarea name="content" placeholder="Content" required="required"></textarea>

进入

<textarea name="content" ></textarea>

现在它可以工作了。如果有原因的答案,我想知道^^

于 2013-09-24T13:10:00.153 回答