开发者

Html.ActionLink and MvcHtmlString

I have a list like below, which is fine:

<ul class="vlistmenu">
    @foreach (var m in Model)
    {开发者_JAVA百科
        <li class="forum">@Html.ActionLink(m.LinkName, "Details", "Forum", new { id = m.Id }, null)</li>
    }
</ul>

Now I'm trying to format the resulting MvcHtmlString from the call to Html.ActionLink and add some more information. But the sample below is not working as I was hoping for.

<ul class="vlistmenu">
    @foreach (var m in Model)
    {
        var link = m.LinkName + "<br /><a style=\"font-size:smaller\">By: Ronron (July 11, 2011)</a>");
        <li class="forum">@Html.ActionLink(link, "Details", "Forum", new { id = m.Id }, null)</li>
    }
</ul>

Basically what I'd like is to append the literal string "By: Ronron (Jull 11, 2011)" to the info from my model, which is m.LinkName. However, I'd like that m.LinkName's font be bigger than the appended literal string. In addition, the literal string should start on the next line not immediately next to m.LinkName. The combined m.LinkName and appended string will form one action link.


if i understood correctly you want to write html attribute to a element so u can declare it on html.actionlink html attributes as you can see on the code ( if you want to add class attribute you need write with @symbol like : new { style = "font-size:smaller", @class = "xClass"}

<ul class="vlistmenu">
@foreach (var m in Model)
{
    var link = m.LinkName + "<br /><a style=\"font-size:smaller\">By: Ronron (July 11, 2011)</a>");
    <li class="forum">@Html.ActionLink(link, "Details", "Forum", new { id = m.Id },  new { style = "font-size:smaller"})</li>
}

Addition for your comment, you can write a custom helper

Raw ActionLink linkText

or you can make manual a tag via url.action method so it will give links according to your controller action but tags implemented manually

<a href="@Url.Action("Details","Forum",new { id = m.Id })">@m.linkname<br /><span style="font-size:smaller">By: Ronron (July 11, 2011)</span></a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜