[index.cshtml]
<ejs-grid id="Grid" allowPaging="true" toolbar="@(new List<string>() {"Add", "Edit", "Update", "Delete" })" actionComplete="actionComplete" actionFailure="onActionFailure">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" template='#dialogtemplate'></e-grid-editSettings>
<e-data-manager url="/Home/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Remove"></e-data-manager>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" type="string" width="120"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script id='dialogtemplate' type="text/x-template">
<div id="dialogTemp">
</div>
</script>
<script type="text/javascript">
function onActionFailure(args) {
var errorMsg ;
// get the error message when failed the validation
if (args.error) {
errorMsg = args.error[0].error.responseText;
} else {
errorMsg = args[0].error.responseText;
}
// Generate error message is show on dialog edit template
var grid = document.getElementById("Grid").ej2_instances[0];
var validationEle = grid.element.querySelector(".e-edit-dialog .form-row div.e-float-input #CustomerID");
var spanEle = document.createElement("span");
spanEle.textContent = '*'+ errorMsg;
spanEle.style.color = "red";
validationEle.parentElement.appendChild(spanEle);
} |