I created a modal window using the following codes:
<% Html.Telerik().Window()
.Name("winCreateUser")
.Title("Create New User")
.Modal(true)
.LoadContentFrom(Url.Action("Create", "Users"))
.Draggable(true)
.Scrollable(true)
.Visible(false)
.Width(750)
.Height(500)
%>
<% Html.Telerik().ScriptRegistrar()
.OnDocumentReady(() => {%>
var createWindow = $('#winCreateUser');
var createButton = $('#createUser');
var w = $('#winCreateUser').data('tWindow');
createButton
.bind('click', function(e) {
w.center().open();
createButton.hide();
})
.toggle(!createWindow.is(':visible'));
createWindow.bind('close', function() {
createButton.show();
});
<%}); %>
LoadContentFrom property is set to a View (aspx) page containing some strongly-typed user input fields, and the associated validation such as the following:
<%: Html.TextBoxFor(model => model.Username) %>
<%: Html.ValidationMessageFor(model => model.Username) %>
<input type="submit" id="createButton" name="create" value="CreateUser" />
The submit button works fine when all input fields were entered correctly. It closes the window and return back to the main window. However, when there are validation errors occur, the modal window will lose its modal state, and the content is displayed in the main window instead. What did I do wrong? Any suggestion is very much appreciated. Thank you.