Load content
24 Oct 20182 minutes to read
By default, the content inside the ContentTemplate property element is considered as the content for the Dialog widget.
Also, we can render the Dialog widget content through the following ways.
-
Request through AJAX
-
Request iframe content
-
Request image content
This settings can be specified through ContentType
property.
NOTE
Create a view page (AjaxContent.cshtml) which contains the content of the dialog.
@{
Html.EJ()
.Dialog("dialog")
.Title("Dialog")
.ContentType("ajax")
.ContentUrl("AjaxContent")
.Render();
}
AjaxContent.cshtml
<div id="content"> This content is loaded via AJAX request. </div>
We can handle the AJAX request’s success and failures through the events “ClientSideOnAjaxSuccess” and “ClientSideOnAjaxError” events respectively.
You can modify the previous example as below to handle the success and failure events.
@{
Html.EJ()
.Dialog("dialog")
.Title("Dialog")
.ContentType("ajax")
.ContentUrl("AjaxContent")
.ClientSideEvents(evt => evt.AjaxSuccess("onSuccess").AjaxError("onError"))
.Render();
}
Add the below script to the view page
<script>
function onSuccess(args) {
//handle success event
}
function onError(args) {
//handle success event
}
</script>
NOTE
The same way we can render the iframe and image content for the Dialog widget by specifying the
ContentType
as “iframe” and “image” respectively and also by specifying the proper location in theContentUrl
property. If you wish to dynamically change the dialog content, you can set theContentUrl
and theContentType
property through setModel on any action.