[index.cshtml]
<ejs-grid id="Grid" allowPaging="true" toolbar="@(new List<string>() {"Add", "Edit", "Update", "Delete" })" actionComplete="actionComplete">
<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" validationRules="@(new { required= true })" textAlign="Right" width="100"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="Name" width="120" foreignKeyField="EmployeeID" foreignKeyValue="FirstName" dataSource="ViewBag.employee"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" type="string" width="120"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" width="120"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
[_DialogAddPartial.cshtml]
<div class="form-row">
<div class="form-group col-md-6">
<div class="e-float-input e-control-wrapper">
<input asp-for="OrderID" type='text' />
<span class="e-float-line"></span>
<label asp-for="OrderID" class="e-float-text e-label-top">Order ID</label>
</div>
</div>
<div class="form-group col-md-6">
<div class="e-float-input e-control-wrapper">
<ejs-dropdownlist id="EmployeeID" dataSource="@ViewBag.employee" placeholder="Employee ID" floatLabelType="Always" popupHeight="300px">
<e-dropdownlist-fields text="FirstName" value="EmployeeID"></e-dropdownlist-fields>
</ejs-dropdownlist>
</div>
</div>
. . . . |
[index.cshtml]
function actionComplete(args) {
if (args.requestType === 'beginEdit' || args.requestType === 'add') {
let spinner = ej.popups.createSpinner({ target: args.dialog.element });
ej.popups.showSpinner(args.dialog.element);
var urlPath = args.requestType == "beginEdit" ? "@Url.Action("Editpartial", "Home")" : "@Url.Action("Addpartial", "Home")";
var stringifydata = args.requestType == "beginEdit" ? JSON.stringify({ value: args.rowData }) : "";
var ajax = new ej.base.Ajax({
url: urlPath, //render the partial view
type: "POST",
contentType: "application/json",
data: stringifydata
});
ajax.send().then(function (data) {
appendElement(data, args.form); //Render the edit form with selected record
if (args.requestType == "beginEdit") {
args.form.elements.namedItem('CustomerID').focus();
} else if (args.requestType == "add") {
args.form.elements.namedItem('OrderID').focus();
}
ej.popups.hideSpinner(args.dialog.element);
}).catch(function (xhr) {
console.log(xhr);
ej.popups.hideSpinner(args.dialog.element);
});
}
} |
type: "POST",
url: '/TestGrid/Index?handler=TestPartial',
contentType: "application/json",
data: stringifydata,
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
success: function (data) {
appendElement(data, args.form); //Render the edit form with selected record
ej.popups.hideSpinner(args.dialog.element);
},
error: function (xhr) {
alert('error : ' + xhr.status + ' - ' + xhr.statusText + ' - ' + xhr.responseText);
console.log(xhr);
ej.popups.hideSpinner(args.dialog.element);
}
})