I have a view in asp.net mvc 3, and I need to open it in a javascript modal. My view has a simple form, like this:
@using(Html.BeginForm("Save", "ControllerName"))
{
@Html.TextBoxFor(model => model.Text)
@Html.ValidationMessageFor(model => model.Text)
<button type="submit">Save</button>
}
I call the showModalDialog like this:
window.showModalDialog('@Url.Action("Show", "ControllerName")');
So, when I press the save button without filling out the inputs, for example, a new window is opened, showing the view with validation erros. Why it happens? Can I submit the form without opening a new window?
Thanks.
Yes, I’ve seen the same thing happening myself when using showModalDialog in IE.
My solution was to open a document that contains a frame (frameset or iframe) with the page you want. The frame can postback without opening a new window.
I would suggest creating a “Dialog” page/view that accepts the real page/view as an argument. In de code, set the src of the frame to that page/view.
As an alternative, you might want to look at the modal stuff that’s in jQuery UI. It created the illusion of being modal without being a real window.