0

我有一个剑道编辑器,定义如下:

@(Html.Kendo().Editor()
                    .Name("myEditor")
                    .Tag("div")
                    .Tools(tools => tools
                            .Clear()
                            .Bold()
                            .Italic()
                            .Underline()
                            .Strikethrough()
                            .JustifyCenter().JustifyFull().JustifyLeft().JustifyRight()
                            .CreateLink().Unlink().TableEditing().FontColor().BackColor())
                     .Value(@<text>
                                Hello Kendo Editor <some text with html tags here>
                        </text>)
                )

然后我有两个仅对管理员显示的按钮 - 保存和编辑,它们的定义如下 -

<button type="button" id="btnedit">Edit</button>
 <input type="submit" name="btnSave"  id="btnSave" value="Save" class="btn btn-default" />

表单上还有其他两个提交按钮,如下所示 -

<input type="submit" name="btnAgree"  id="btnAgree"  value="Agree" class="btn btn-primary" />
<input type="submit" name="btnDisagree" id="btnDisagree" value="Disagree" class="btn btn-default" />

表单通过使用 BeginForm("ActionMethod", "Controller", FormMethod.Post) 来处理同意和不同意按钮的提交,如下所示 -

@using (Html.BeginForm("Index", "MyControllerName", FormMethod.Post))

现在我想要这样,当管理员用户进入并对编辑器文本进行更改并点击“保存”按钮时,我希望编辑器的文本保存在数据库中。我可以处理储蓄部分。我只想知道,如何从 Kendo Editor 中获取文本并将文本值发送到控制器中的 action 方法。

我在这里尝试了此线程中提供的解决方案 - http://www.telerik.com/forums/save-changes-to-and-print-content-of-editor-in-mvc

因此,使用此处的解决方案,我添加了一个操作方法,其字符串参数名称类似于编辑器名称,如下所示 -

public ActionResult Save(string myEditor) {

// TO DO: Save the text to the database

 }

当我运行我的应用程序并点击“保存”按钮时,我收到以下错误 -

HTTP 错误 404.0 - 导航无效 您要查找的资源已被删除、名称已更改或暂时不可用。

它没有点击“保存”操作方法。我怎样才能让它工作?

谢谢

4

2 回答 2

2

我所做的是以下(对于迟到的回复已经抱歉)

$("form").on("submit", function () {
    var form = $(this);

    // for each editor in the form
    form.find("[data-role=editor]").each(function () {
        var editor = $(this).data("kendoEditor");

        // ... add value of the editor to a hidden input
        $("#Description").val(editor.value());
    });


    $.post(saveOrUpdateEditor, $('#contentEditorKendo').serialize(),
        function (data) {

        });
});

还请务必在执行此操作时将编辑器包装在一个表格中如果您有更多问题,请联系

于 2018-05-04T11:04:47.063 回答
0

您是否考虑过使用AJAX呼叫来发送内容myEditor

您需要将<input> type属性更改为 justbutton以便它不被视为提交并连接onclick事件处理程序:

<input type="button" name="btnSave"  id="btnSave" value="Save" class="btn btn-default" onclick="save()" />

然后连接将处理您的 AJAX 调用的相关 Javascript 函数:

function save() {
    var enteredText = $("#myEditor").data("kendoEditor").value();
    alert(editor.value());
    $.ajax({
        type: 'post',
        dataType: 'json',
        url: 'yourController\Save',
        data: { "myEditor": JSON.stringify(enteredText) },
        success: function (response) {
            // handle a response following database operations
        },
    });
}); 

并且不要忘记使用相关的请求方法(在本例中POST)装饰您的控制器方法:

[HttpPost]
public ActionResult Save(string myEditor) {
    // TO DO: Save the text to the database
}
于 2017-05-09T14:34:33.430 回答