2014-07-11 26 views
1

我有:如何CSS類應用到HTML鏈接行動剃刀

<p><a class="btn btn-default" href="~/Person">List of Cients &raquo;</a></p>

我想與HTML鏈接的行動來代替它,但不改變的視覺風格。

我想要去Index行動PersonController

公共類PersonController:控制器 { 私人PersonContext DB =新PersonContext();

// GET: Person 
    public ActionResult Index() 
    { 
     return View(db.Persons.ToList()); 
    } 
} 

@Html.ActionLink(...)應該是什麼樣子。

編輯:

我想:

<p><a class="btn btn-default" href="~/Person">List of Cients &raquo;</a></p> 
     @Html.ActionLink("List of Clients &raquo", "Index", "Person", new { @class = "btn btn-default" }) 

還有就是問題:&raquo; ActionLink的不渲染preetty箭頭。

EDIT2:

沒有結果嘗試這樣:@Html.ActionLink("List of Clients " + HttpUtility.HtmlDecode("&raquo"), "Index", "Person", new { @class = "btn btn-default" })

編輯: 兩個不工作。

<p> @Html.ActionLink("List of Clients »", "Index", "Person", new { @class = "btn btn-default" })</p> 
     <p> @(Html.ActionLink("List of Clients »", "PersonController/Index", new { @class = "btn btn-default" })); 

首先給出正確的風格,但當我點擊我在鏈接中得到length=6。 二沒有風格和鏈接:http://localhost:17697/Home/PersonController/Index?class=btn%20btn-default

答:這一件作品:

<p> @Html.ActionLink("List of Clients »", "Index", "Person", null, new { @class = "btn btn-default" })</p>

回答

2

@(Html.ActionLink("Title", "/PersonController/Index", new { @class = "myCssClass" }));

下面是引用鏈接:http://msdn.microsoft.com/en-us/library/dd492124(v=vs.108).aspx

+0

»是不理解的ActionLink的 這筆交易,有preetty''>>在一部開拓創新的鏈接: '

List of Cients »

'||| '@ Html.ActionLink(「客戶名單&raquo」,「索引」,「人員」,新{@class =「btn btn-default」})' –

+0

那麼這項工作呢?..我現在明白你的問題了。 ..你應該在問題中提及它。你在問題 – Ani

+0

中問了課,他們不工作。請看OP中的最後一個編輯。 –

0

請嘗試這,它會工作

<a href="@Url.Action("Index", "Person")"> 
    <button class="btn btn-default"> 
     List of Cients &raquo; 
    </button> 
    </a> 
0

試試這個

@Html.ActionLink("ButtonText", "Action","Controller", new {@class="btn btn-default"}) 

這對我工作。

注意: new {@class="btn btn-default"}在第三個逗號之後。

0
<pre> 
<p>I will display &#187;</p> 
<div> 
     @Ajax.ActionLink("Contact " + HttpUtility.HtmlDecode("&#187;"), 
        "_PartialEmployeeIndex", "Employee", 
         new AjaxOptions() { UpdateTargetId = "divToUpdate" }, 
        new { @class = "btn btn-primary" }) 
    </div> 
</pre>