In my MVC project, I have a view which displays a list of roles (as in user roles), and an add button, which pops up a KendoUI window, rendering a Create view.
This is how my window snippet looks like:
And this is what I use to open(popup) and close the window
My question is, how do I close the window, if and only if the action is successful?
I would like to know how to handle the portions that I have commented.
Basically, if the role is added succesfully, I would like the window to close automatically, taking me back to my list of roles, which I will then update. If there's any kind of error, the window will remain open, showing an error msg.
This is how my window snippet looks like:
@(Html.Kendo().Window() .Name("window") .Title("Role") .Content("loading...") .LoadContentFrom("Create", "RolesPermissions", Model.Role) .Modal(true) .Width(550) .Height(300) .Visible(false) )
And this is what I use to open(popup) and close the window
$(document).ready(function () { var wnd = $("#window").data("kendoWindow"); wnd.bind("refresh", function (e) { var win = this; $("#close").click(function() { win.close(); }); }); $("#open").click(function (e) { wnd.center(); wnd.open(); }); });
My question is, how do I close the window, if and only if the action is successful?
[HttpPost] public ActionResult Create(RoleModel model) { if (ModelState.IsValid) { RoleDto role = new RoleDto { Name = model.Name, Description = model.Description }; var roleAdded = _rolePermissionsRepository.AddRole(role); if (roleAdded != null) { //CLOSE KENDOUI WINDOW } else { //PRINT ERROR MSG TO KENDOUI WINDOW } } return View(); }
I would like to know how to handle the portions that I have commented.
Basically, if the role is added succesfully, I would like the window to close automatically, taking me back to my list of roles, which I will then update. If there's any kind of error, the window will remain open, showing an error msg.