2016-05-05 39 views
0

我想在MVC上点击ActionLink来打开使用引导程序的弹出窗口。这里是我的代码 -mvc中的Bootstrap Popup

@Html.ActionLink("Create New", "Bootstrap", null, new { @class = ".mymodal" }) 

@using (Html.BeginForm()) 
{ 
<div class="modal fade mymodal"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      //Next lines of code 
    </div> 
</div> 
</div> 
} 

但弹出不会打开。那么鉴于其对按钮的点击打开如下─

<a class="btn btn-success" data-toggle="modal" data-target=".mymodal"> <span class="glyphicon glyphicon-eye-open"></span>View</a> 
+0

锚标记你尝试过这个http://stackoverflow.com/questions/24017306/jquery-open-popup-on-bu tton-click-for-bootstrap –

+0

我觉得你没有明白我的观点。我想打开弹出单击ActionLink NOT ON按钮单击 –

回答

0

给ID到你的模式和运行触发像

$("#modal").modal("show"); 
1

您需要添加这些数据属性您ActionLinkHtmlAttributes,如下。

@Html.ActionLink("Create New", "Bootstrap", null, new { @class = "btn btn-success", data-toggle="modal", data-target=".mymodal", id = "yourButtonID" }) 

您还可以定义一个Click事件在JQuery中的ActionLink的,并调用一个jQuery方法打开模态,如下:请注意,你需要给你的HtmlAttributesActionLink一个id,按规定:

$(function() { 
    $(document) 
     .on("click", "#yourButtonID", function() { 
      showModal(); 
    }); 

    function showModal() { 
     //set options here if needed. 
     $("#YourModalID").modal('show'); 
    } 
}) 
+0

谢谢,它的工作 –

+0

@RiteshGupta请标记为接受的解决方案。 –

0

更新你这一个

@Html.ActionLink("Create New", "Bootstrap", null, new { @class="btn btn-success" data-toggle="modal" data-target=".mymodal" })