2016-05-05 43 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" })