Search results

Server actions in ASP.NET Core In-place Editor control

17 Sep 2021 / 2 minutes to read

By passing In-place Editor control value to the server, the primaryKey property value must require, otherwise action not performed for remote data.

If the url property value is empty, data passing will handled at local and also the actionSuccess event will trigger with null as argument value.

The following arguments are passed to the server when submit actions perform.

Arguments Explanations
value For processing edited value, like DB value updating.
primaryKey For value mapping to the server, like selecting DB.
name For field mapping to the server, like DB column field mapping.

Find the following sample server codes for defining models and controller functions to configure processing data.

Copied to clipboard
    public class SubmitModel
        {
            public string Name { get; set; }
            public string PrimaryKey { get; set; }
            public string Value { get; set; }
        }
Copied to clipboard
public IEnumerable<SubmitModel> UpdateData([FromBody]SubmitModel value)
        {
         // User can process data
          return value;
        }
  • Server actions successfully done, the actionSuccess event will be fired with returned server data.
  • If the server is not responding, the actionFailure event will be fired with data, but value not updated in the Editor.

In the following sample, the actionSuccess event will trigger once the value submitted successfully into the server. In this sample, both actionSuccess and actionFailure were configured and resulted value will be converted to chips.

tagHelper
controller.cs
Copied to clipboard
<div id='container'>
    <span class="content-title"> Select frameworks: </span>
    <ejs-inplaceeditor id="element" mode="Inline" type="MultiSelect" value="ViewBag.value" name="skill" url="https://ej2services.syncfusion.com/development/web-services/api/Editor/UpdateData" primaryKey="FrameWork" created="created" adaptor="UrlAdaptor" model="ViewBag.model" actionSuccess="actionSuccess" actionFailure="actionFailure">
    </ejs-inplaceeditor>
</div>

<style>

    #container {
        margin: 0 auto;
        width: 600px;
    }
</style>
<script>
    function created() {
        chipOnCreate();
        document.getElementById("element").setAttribute("data-underline", "false");
    }
    function actionSuccess(e) {
        e.value = chipCreation(e.value.split(','), true);
    }
    function actionFailure(e) {
        e.value = chipCreation(e.value.split(','), false);
    }
    function chipOnCreate() {
        var editObj = document.getElementById('element').ej2_instances[0];
        editObj.element.querySelector('.e-editable-value').innerHTML = chipCreation(editObj.value);
    }
    function chipCreation(data, isSuccess) {
        var value = '<div class="e-chip-list">';
        [].slice.call(data).forEach((val) => {
            value += '<div class="e-chip"> <span class="e-chip-text' + (!isSuccess ? 'e-highlight' : '') + '"> ' + val + '</span></div>';
        });
        value += '</div>';
        return value;
    }
</script>
Copied to clipboard
public class HomeController : Controller
{
    public ActionResult Index()
    {
        var frameWorkList = new string[] { "Android", "JavaScript", "jQuery", "TypeScript", "Angular", "React", "Vue", "Ionic" };
        ViewBag.model = new { mode = "Box", dataSource = frameWorkList, placeholder = "Select skill" };
        ViewBag.url = "https://ej2services.syncfusion.com/development/web-services/api/Editor/UpdateData";
        ViewBag.value = new string[] { "JavaScript", "jQuery" };
        return View();
    }
}

The output will be as follows.

server-actions

See Also