Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax modal not displaying correctly #417

Open
kirbinator2016 opened this issue Mar 12, 2016 · 4 comments
Open

Ajax modal not displaying correctly #417

kirbinator2016 opened this issue Mar 12, 2016 · 4 comments

Comments

@kirbinator2016
Copy link

Please forgive me because this is the first time I've used TwitterBootstrapMVC. I am using Dimitry's recommended approach listed here for loading up a modal form:

http://stackoverflow.com/questions/16011151/mvc-4-edit-modal-form-using-bootstrap/19039695#19039695?newreg=8f7857ae5e92417fa88be962d169e67d

When I run this sample, I do get a modal that I can dismiss, but the modal is nearly as wide as the browser window and has a transparent background. When I run some of the samples of opening a modal (not using AJAX), everything appears to work great. But opening the modal using the helper method, things just don't look right at all.

Any suggestions?

@DmitryEfimenko
Copy link
Owner

Could you please show the issue in a sample project?

@kirbinator2016
Copy link
Author

Thank you very much for responding so quickly. I have attached an MVC5 very basic web application. It basically mimics what you posted in stackoverflow. On the Index page I have a grid that uses AJAX for opening the modal. I also included a simple button demonstrating opening a modal in a non-AJAX manner. Both are examples that you are familiar with because you wrote the code.

You should see pretty quickly what I'm talking about in the AJAX version.

@kirbinator2016
Copy link
Author

Hi Dmitry, I think I know what the issue is. I determined that the PartialView "GetPersonInfo" needs to be wrapped with 2 DIV's (one with a class of "modal-dialog" and one with a class of "modal-content"). So now the question is, what is the appropriate syntax that I should use in the partial class?

@{
    // get modal helper
    var modal = Html.Bootstrap().Misc().GetBuilderFor(new Modal());
}

<div class="modal-dialog ">
    <div class="modal-content">
        @modal.Header("Edit Person")
        @using (var f = Html.Bootstrap().Begin(new Form()))
        {
            using (modal.BeginBody())
            {
                @Html.HiddenFor(x => x.Id)
                @f.FormGroup().TextBoxFor(x => x.Name)
                @f.FormGroup().TextBoxFor(x => x.Age)
            }
            using (modal.BeginFooter())
            {
                // if needed, add here @Html.Bootstrap().ValidationSummary()
                @:@Html.Bootstrap().Button().Text("Save").Id("btn-person-submit")
                @Html.Bootstrap().Button().Text("Close").Data(new { dismiss = "modal" })
            }
        }
    </div>
</div>

@DmitryEfimenko
Copy link
Owner

Thanks for the sample app. I quickly found the issue and updated answer on StackOverflow.
There are two changes:
In GetPersonInfo ActionResult change:

return View("GetPersonInfo", model);

to:

return PartialView("GetPersonInfo", model);

Second, in the index.html change success function of the ajax call to /Person/GetPersonInfo to this:

var m = $('#modal-person');
m.find('.modal-content').html(data);
m.modal('show');

This should be it. Let me know if you still have issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants