|
CSHTML
<form id="form1" method="post">
<div style="display:none">
@{
Html.EJ().Dialog("basicDialog",Model).Render(); // render the Dialog in view
}
</div>
<div>
@Html.EJ().Button("btnOpen").Type(ButtonType.Submit).Text("Click to check").ClientSideEvents(evt => evt.Click("onclick"))
</div>
</form>
CONTROLLER
public ActionResult Index()
{
Syncfusion.JavaScript.Models.DialogProperties dia = new Syncfusion.JavaScript.Models.DialogProperties();
dia.ShowOnInit = false; // initially set as false
return View(dia);
}
[HttpPost]
public ActionResult Index(string basicDialog)
{
int a = 1;
int b = 0;
int c = 0;
try
{
c = a / b; //try the code here
}
catch (Exception ex)
{
Syncfusion.JavaScript.Models.DialogProperties dia = new Syncfusion.JavaScript.Models.DialogProperties();
dia.ShowOnInit = true;
dia.Title = "Error Message";
dia.ContentTemplate = new MvcTemplate<object>
{
RazorViewTemplate = (data) =>
{
return ex; // return the error message in the Dialog content template like this
}
};
return View(dia);
}
return View();
}
}
|
@model PLV.Web.Models.ViewModels.LoginVM <div id="dvform"> @{Html.EJ().Dialog("dialog", (Syncfusion.JavaScript.Models.DialogProperties)ViewBag.Dia).Render(); } @using (Ajax.BeginForm("Index", "Login", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "dvform" })) { @Html.AntiForgeryToken() <div class="col-lg-6 col-sm-6 col-lg-offset-3 col-sm-offset-3"> <div class="row"> <div class="form-group "> @Html.LabelFor(m => m.Codice) @Html.EditorFor(m => m.Codice, new { htmlattributes = new { @class = "form-control input-lg" } }) @Html.ValidationMessageFor(m => m.Codice, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(m => m.Password) @Html.PasswordFor(m => m.Password, new { @class = "form-control input-lg" }) @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" }) </div> <hr /> <input type="submit" value="@PLV.Web.Resources.Login.Accedi" class="buttoncolor" /> <a rel='nofollow' href="@Url.Action("RecuperoPassword","Login")" class="buttonyellow"> @(PLV.Web.Resources.Login.RecuperaPassword)</a> @if (TempData["error"] != null) { <div class="alert alert-danger" role="alert">@TempData["error"]</div> } </div> </div> } </div>
public ActionResult Index() { log4net.Config.XmlConfigurator.Configure(); log.Info("Inizio esecuzione Index()"); try { Syncfusion.JavaScript.Models.DialogProperties dia = new Syncfusion.JavaScript.Models.DialogProperties(); dia.ShowOnInit = false; ViewBag.Dia = dia; log.Info("Fine esecuzione Index()"); } catch (Exception ex) { log.Error(string.Format("Errore:{0}", ex.InnerException == null ? ex.Message : ex.InnerException.Message)); throw ex; } return View(); }
TempData["error"] = Resources.Login.CredenzialiErrate; Syncfusion.JavaScript.Models.DialogProperties dia = new Syncfusion.JavaScript.Models.DialogProperties(); dia.ShowHeader = true; dia.Title = "Error Message"; dia.ContentTemplate = new MvcTemplate<object> { RazorViewTemplate = (data) => { return "<div> Message </div>"; // return the error message in the Dialog content template like this } }; dia.ShowOnInit = true; ViewBag.Dia = dia; return PartialView("_Login");
|
_Login.Cshtml
@{
ViewBag.Title = "DialogPartial";
Layout = "~/Views/Shared/_Layout.cshtml"; // refer the layout page
}
////// your partial page content
|