2017-05-09 67 views
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" /> 

而且FO RM处理提交的同意并通过BeginForm不同意按钮(“ActionMethod”,“控制器”,FormMethod.Post)像下面 -

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

现在我想的是,当一个管理员用户进来,使得变化到编辑器文本并点击'保存'按钮,我希望编辑器的文本保存在数据库中。我可以处理保存部分。我只想知道,我如何从Kendo Editor获取文本并将文本值发送到控制器中的操作方法。

我想在这个线程这里提供的解决方案 - 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 Error 404.0 - Invalid navigation The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

它不打“保存”操作方法。我如何得到这个工作?

感谢

回答

0

有你为了送myEditor内容使用AJAX通话考虑?

你需要改变<input>type属性只是button所以它不被视为一个提交和挂钩的onclick事件处理程序:

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

然后勾了关联的JavaScript功能,将处理您的AJAX调用:

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 
} 
+0

谢谢@Sandman的回答。我尝试了上面的方法,但是当它试图从Kendo Editor获取值时,我收到了Javascript错误。 0x800a138f - JavaScript运行时错误:无法获取未定义或空引用的属性“值” – Kristy

+0

确保您正在访问[现有实例](http://docs.telerik.com/aspnet-mvc/helpers/editor/overview#existing -instances)在你的MVC声明之后。 – Sandman