[Index.cshtml.cs]
public ActionResult OnPostEditPartial([FromBody]CRUDAction<DialogTemplateModel> value)
{
return new PartialViewResult
{
ViewName = "_EditPartial",
ViewData = new ViewDataDictionary<DialogTemplateModel>(ViewData, value.value)
};
}
public ActionResult OnPostAddPartial()
{
return new PartialViewResult
{
ViewName = "_AddPartial"
};
} |
<ejs-grid id="Grid" load="onLoad" actionComplete="actionComplete" toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel"})">
<e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" template='#dialogtemplate'></e-grid-editsettings>
</ejs-grid>
<script id='dialogtemplate' type="text/x-template">
<div id="dialogTemp">
</div>
</script>
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);
if (args.requestType === 'beginEdit') {
var ajax = new ej.base.Ajax({
type: "POST",
url: "/Index?handler=EditPartial",
beforeSend: function (xhr) {
ajax.httpRequest.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
contentType: "application/json",
dataType: 'json',
data: JSON.stringify({ value: args.rowData })
});
ajax.send().then(function (data) {
appendElement(data, args.form);
args.form.elements.namedItem('CustomerID').focus();
ej.popups.hideSpinner(args.dialog.element);
}).catch(function (xhr) {
console.log(xhr);
ej.popups.hideSpinner(args.dialog.element);
});
}
if (args.requestType === 'add') {
var ajax = new ej.base.Ajax({
type: "POST",
url: "/Index?handler=AddPartial",
beforeSend: function (xhr) {
ajax.httpRequest.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
contentType: "application/json",
dataType: 'json'
});
ajax.send().then(function (data) {
$("#dialogTemp").html(data);
args.form.elements.namedItem('OrderID').focus();
ej.popups.hideSpinner(args.dialog.element);
}).catch(function (xhr) {
console.log(xhr);
ej.popups.hideSpinner(args.dialog.element);
});
}
}
} |
Hi diego,
From validating your query, we understand you want to use dialogTemplate with razor page. So based on your query we have prepared a sample of dialogTemplate with razor page. Please refer the below code example, sample and documentation for more information.
[Index.cshtml.cs]public ActionResult OnPostEditPartial([FromBody]CRUDAction<DialogTemplateModel> value){return new PartialViewResult{ViewName = "_EditPartial",ViewData = new ViewDataDictionary<DialogTemplateModel>(ViewData, value.value)};}public ActionResult OnPostAddPartial(){return new PartialViewResult{ViewName = "_AddPartial"};}
<ejs-grid id="Grid" load="onLoad" actionComplete="actionComplete" toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel"})"><e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" template='#dialogtemplate'></e-grid-editsettings></ejs-grid><script id='dialogtemplate' type="text/x-template"><div id="dialogTemp"></div></script>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);if (args.requestType === 'beginEdit') {var ajax = new ej.base.Ajax({type: "POST",url: "/Index?handler=EditPartial",beforeSend: function (xhr) {ajax.httpRequest.setRequestHeader("XSRF-TOKEN",$('input:hidden[name="__RequestVerificationToken"]').val());},contentType: "application/json",dataType: 'json',data: JSON.stringify({ value: args.rowData })});ajax.send().then(function (data) {appendElement(data, args.form);args.form.elements.namedItem('CustomerID').focus();ej.popups.hideSpinner(args.dialog.element);}).catch(function (xhr) {console.log(xhr);ej.popups.hideSpinner(args.dialog.element);});}if (args.requestType === 'add') {var ajax = new ej.base.Ajax({type: "POST",url: "/Index?handler=AddPartial",beforeSend: function (xhr) {ajax.httpRequest.setRequestHeader("XSRF-TOKEN",$('input:hidden[name="__RequestVerificationToken"]').val());},contentType: "application/json",dataType: 'json'});ajax.send().then(function (data) {$("#dialogTemp").html(data);args.form.elements.namedItem('OrderID').focus();ej.popups.hideSpinner(args.dialog.element);}).catch(function (xhr) {console.log(xhr);ej.popups.hideSpinner(args.dialog.element);});}}}
And from validating your query, we have seen your provided code example we are not getting your exact requirement and what you are trying to achieve. So before start providing the better solution please share the below details that will be helpful for us to provide better solution.
1) Please share your exact requirement scenario and explain what are you going to achieve.
2) If you are facing any issue, please share the screenshot and if possible please reproduce the issue with our above attached sample.
Regards,Rajapandi R