2014-06-09 126 views
1

有人可以幫我這個ActionLink的我想開一個隱藏的DIV在剃刀,剃刀ActionLink的開彩盒

這是鏈接,

<a class='inline' href="#inline_content">Inline HTML</a> 

這是腳本,

<script> 
    $(document).ready(function() { 
     $(".inline").colorbox({ inline: true, width: "50%" }); 
    }); 
</script> 

而且也是事業部,

<p><a class='inline' href="#inline_content">Inline HTML</a></p> 

<div style='display:none'> 
    <div id='inline_content' style='padding:10px; background:#fff;'> 

     <p><strong>This content comes from a hidden element on this page.</strong></p> 

     <p>The inline option preserves bound JavaScript events and changes, and it puts the content back where it came from when it is closed.</p> 

    </div> 
</div> 

編輯

我需要在MVC Razor風格的ActionLink中重寫HTML鏈接,代碼可以在HTML中正常工作,但不在Razor中。 HTML鏈接發佈到Razor的新頁面,所以我想我需要一個ActionLink來發布到腳本。

<a class='inline' href="#inline_content">Inline HTML</a> 

e.g ..

@Html.ActionLink("Inline HTML", null, null, new { Class="inline", onclick = "#inline_content();" }); 
+0

http://stackoverflow.com/questions/1974980/putting-html-inside-html-actionlink-plus-no-link-text – rjdmello

回答

0

你的問題只涉及HTML和jQuery。您可以通過將點擊事件綁定到錨標記來顯示隱藏的內容。

的jsfiddle here

$("a.inline").on('click',function(){ 
    $("#inline_content").parent().show(); 
    return false; 
}); 
0

嘗試這樣,

@Html.ActionLink("Inline HTML", null, null, new { Class="inline", onclick = "Show_Div_content();" }); 


<script type="text/javascript"> 
    function Show_Div_content() { 
     $("#inline_content").parent().show(); 
    } 
</script> 
0

Html.ActionLink是用於返回基於傳遞給它的參數的錨定元件的LinkExtensions類(http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink(v=vs.118).aspx)的一部分。對我來說,這裏你唯一的動作就是打開一個彩盒。

<a class='inline' href="#inline_content">Inline HTML</a> 

使用上述應該沒問題,因爲你沒有路由任何東西。

+0

謝謝邁克爾,我的MVC技能是相當不錯的,我可以用圖像做到這一點一些JavaScript在剃刀中被稱爲Visual Light Box,但我對ColorBox不太熟悉。我應該使用@ Url.Content嗎?發生了什麼事情,我最終得到一個以/ Home/Index/1#inline_content結尾但沒有ColorBox彈出窗口的URL。 – Bojangles

+0

是的,因爲ActionLink會根據你的實際位置返回一個鏈接,因爲這裏是/ Home/Index /,因爲這不是一個控制器動作,你只是通過使用基本錨點元素而沒有犯罪。 –