Using Bootstrap Modal window as PartialView

后端 未结 5 1001
南方客
南方客 2020-11-27 10:05

I was looking to using the Twitter Bootstrap Modal windows as a partial view. However, I do not really think that it was designed to be used in this fashion; it seems like

5条回答
  •  春和景丽
    2020-11-27 10:47

    Yes we have done this.

    In your Index.cshtml you'll have something like..

    
    
    
    

    Then in JS for the same page (inlined or in a separate file you'll have something like this..

    $(document).ready(function() {
       $('#showGame').click(function() {
            var url = $('#gameModal').data('url');
    
            $.get(url, function(data) {
                $('#gameContainer').html(data);
    
                $('#gameModal').modal('show');
            });
       });
    });
    

    With a method on your controller that looks like this..

    [HttpGet]
    public ActionResult GetGameListing()
    {
       var model = // do whatever you need to get your model
       return PartialView(model);
    }
    

    You will of course need a view called GetGameListing.cshtml inside of your Views folder..

提交回复
热议问题