2017-05-09 71 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