代码之家  ›  专栏  ›  技术社区  ›  Stefan0309

Bootstrap 4和MVC5打开模态作为partialView

  •  0
  • Stefan0309  · 技术社区  · 6 年前

    我读过 this post

    我的HTML:

     <div id='gameModal' class='modal hide fade in' data-url='@Url.Action("TermsAndConditions","Base")'>
     <div id='gameContainer'/>
     <button id='showGame'>Show Game Listing</button></div>
    

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

    我还用partialView创建了一个控制器:

     [HttpGet]
     public ActionResult TermsAndConditions()
      {
         return PartialView();
      }
    

    我发现我的js文件中的一行被跳过:$.get(url,function(data))

    而不是像“/Base/TermsAndConditions”这样的“正常”路由 “/en-US/Base/TermsAndConditions” 有没有提示如何在没有额外参数的情况下设置url而不拆分url和mambo jumbo之类的东西?

    这是我的路由配置:

     public class RouteConfig
     {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                name: "Default",
                url: "{language}/{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, language = "en-US" }
            );
        }
    }
    

    有没有更现代的方法用partialview打开情态动词? 更新: 我已经设法查看了我的模式,但只有在我的示例布局页面中的按钮旁边放置了部分查看HTML代码时,才会这样做:

    <button class="btn btn-primary" data-toggle="modal" data-url='@Url.Action("TaC","Home")' data-target=".bs-example-modal-lg">Large modal</button>
     <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
      <div class="modal-body">
         <div class="modal-content">
           <div class="modal-header">
             <h4 class="modal-title" id="myModalLabel">Modal Heading</h4>
             <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
    <div class="modal-body">
    <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. 
    Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
    <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>                        
            </div>
          </div>
        </div>
      </div>
    </div>
    

    如果我把数据url=@url.Action(“Index”,“Home”)它不会到达控制器。

    0 回复  |  直到 6 年前