RadControls for ASP.NET AJAX

RadControls for ASP.NET AJAX

Using RadEditor in ASP.NET MVC

1. RadEditor needs to be placed inside a form tag

2. To use RadEditor’s dialog you need to change the extension of the dialog HTTP handler (in web.config):Before:

CopyXML
<add path="Telerik.Web.UI.DialogHandler.aspx" ... />

After:

CopyXML
<add path="Telerik.Web.UI.DialogHandler.axd" ... />

and set the DialogHandlerUrl property:

CopyASPX
<telerik:RadEditor runat="server" ID="RadEditor1" 
    DialogHandlerUrl="~/Telerik.Web.UI.DialogHandler.axd"  />

Getting the content of RadEditor

To get the content of your RadEditor you need to use a helper method. Here is its implementation (the code is also available as part of the RadControlHelper class):

CopyC#
public static string ExtractHtmlValue(HttpRequestBase request, string controlId)
{
     return request.Form.Keys.OfType<string>()
        .Where(postedValue => postedValue.EndsWith(controlId))
        .Select(postedValue => request.Form[postedValue])
        .FirstOrDefault();
}

public static string ExtractStringValue(HttpRequestBase request, string editorId)
{
 return Telerik.Web.UI.Editor.ContentEncoder.Decode(ExtractHtmlValue(request, editorId));
}

Here is how to use it:

CopyC#
public ActionResult Save()
{
   string editorContents = RadControlHelper.ExtractHtmlValue(Request, “”
  //Code to update your model using the editor content
}

Setting the content of RadEditor

To set the content of RadEditor you need to set the value of its Content property:

CopyASPX
<% RadEditor1.Content = (string)ViewData["Content"]; %>

<form>     
    <telerik:RadEditor runat="server" ID="RadEditor1" />

See Also

Other Resources