【问题标题】:How to open bootstrap modal without posting back?如何在不回发的情况下打开引导模式?
【发布时间】:2018-03-30 07:28:54
【问题描述】:

在一个View中,有一个文件上传控件(下面的代码除外),两个按钮,一个用于保存,一个用于显示模态。

@using (Html.BeginForm("Display", "Home", FormMethod.Post, 
new {enctype = "multipart/form-data"}))
{ 
    <div id="myModal" class="modal fade" role="dialog"> 
        <div class="modal-dialog">
            <div class="modal-content">
               <div class="modal-body">
               </div>
            </div>
         </div>
    </div><button id="btn1" name="update" class="btn btn-danger" type="submit">Save</button><br />
    <button id="btn2" name="savenadd" class="btn btn-danger" data-toggle="modal" data-target="#myModal">Display Modal</button>
}

当点击 btn2 时如何防止页面回发?我不介意在模态关闭时发回。谢谢

【问题讨论】:

    标签: asp.net-mvc twitter-bootstrap


    【解决方案1】:

    WC3 标准指定&lt;form&gt;&lt;button&gt; 的默认typetype="submit"。为防止出现默认行为,请将其设为type="button"(注意name 属性不是必需的)

    <button id="btn2" type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal">Display Modal</button>
    

    或者,您可以将按钮移到 &lt;form&gt; 元素之外。

    【讨论】:

      猜你喜欢
      • 2015-05-23
      • 2019-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多