Skip to main content

Getting Editor Values

  • 2 minutes to read

Editors from Data Editors Extensions provide specific server and client methods, allowing you to access an editor’s edited value.

 

  • On the Server Side - Use the static EditorExtension.GetValue<T> method to access the value of a specific editor.

    This method is intended to be used within Controllers. It requires you to specify the name of an editor whose value is to be obtained (SettingsBase.Name) and indicate the type of the returned value.

    The simplest overload of the GetValue method allows you to obtain an editor’s value in the following manner:

    Controller code (“HomeController.cs”):

    // ...
    using MyWebApplication.Models;
    using DevExpress.Web.ASPxEditors;
    using DevExpress.Web.Mvc;
    // ...
    
        public class HomeController : Controller {
            // ...
            [HttpPost]
            public ActionResult Editing(Product item) {
                // Get the value stored in "ProductName" field.
                string value = EditorExtension.GetValue<string>("ProductName");
                return View();
            }
            // ...
        }
    

    View code (Razor):

    @model MyWebApplication.Models.Product
    
    @using (Html.BeginForm("Editing", "Home", FormMethod.Post))
    {
        @Html.DevExpress().TextBox(settings => {
            settings.Name = "ProductName";
        }).Bind(Model.ProductName).GetHtml()
    
        @Html.DevExpress().Button(settings => {
            settings.Name = "btnUpdate";
            settings.Text = "Update";
            settings.UseSubmitBehavior = true;
        }).GetHtml()
    }
    

    More complex EditorExtension.GetValue method overloads allow you to validate the editor value (based on specific validation settings or custom validation logic). They also indicate whether the obtained value is valid.

    To learn more, see our online demos:

     

  • On the Client Side - Use an editor’s client ASPxClientEditBase.GetValue method.

    View code (ASPX):

    <% 
        Html.DevExpress().Button(
            settings => {
                settings.Name = "button1";
                settings.Text = "Get TextBox Value";
                settings.ClientSideEvents.Click = "function (s, e){label1.SetText(textBox1.GetValue());}";
            }
        )
        .Render();
    %>
    
    <% 
        Html.DevExpress().TextBox(
            settings => {
                settings.Name = "textBox1";
                settings.Properties.EnableClientSideAPI = true;
            }
        )
        .Render();
    %>
    
    <% 
        Html.DevExpress().Label(
            settings => {
                settings.Name = "label1";
                settings.Properties.EnableClientSideAPI = true;
            }
        )
        .Render();
    %>
    

    View code (Razor):

    @Html.DevExpress().Button(
            settings => {
                settings.Name = "button1";
                settings.Text = "Get TextBox Value";
                settings.ClientSideEvents.Click = "function (s, e){label1.SetText(textBox1.GetValue());}";
            }
        ).GetHtml()
    
    @Html.DevExpress().TextBox(
            settings => {
                settings.Name = "textBox1";
                settings.Properties.EnableClientSideAPI = true;
            }
        ).GetHtml()
    
    @Html.DevExpress().Label(
            settings => {
                settings.Name = "label1";
                settings.Properties.EnableClientSideAPI = true;
            }
        ).GetHtml()