coder25
coder25

Reputation: 2393

html.actionlink take C# variable as parameter

 <% foreach (var item in Model) { %>

        <table width="100%" class="topicContainer">
           <tr>
             <td>  <%: Html.DisplayFor(modelItem => item.headerclob) %></td>
            </tr>
            <tr>
             <td><%: Html.ActionLink("ViewTopic", "ViewTopic","Forum" ,
               new { id=item.topicId },null) %></td>
            </tr>
        </table>

       <% } %>

I want of link ViewTopic item.headerclob should be displayed in hyperlink without using Razor.

I also want to apply css to it.

Upvotes: 1

Views: 5906

Answers (1)

Jayanga
Jayanga

Reputation: 887

I think the below code should work

<%: Html.ActionLink("item.headerclob, "ViewTopic","Forum" ,
               new { id=item.topicId },null) %>

it use the following format

public static string ActionLink(this HtmlHelper htmlHelper, 
                                string linkText,
                                string actionName,
                                string controllerName,
                                object values, 
                                object htmlAttributes)

if you are using MVC 3 then the you can just use "item.topicId" instead of "id = item.topicId"

Edited yes it works but after removing semicolon from item.headerClob

    <%: Html.ActionLink(item.headerclob, "ViewTopic","Forum" ,
               new { id=item.topicId },null) %>

Edit add a class to action link then use your css file for setting necessary properties

<%: Html.ActionLink(item.headerclob, "ViewTopic","Forum" ,
                   new { id=item.topicId , @class = "YourClass"},null) %>

now you can apply css properties to the action link you set css properties to others

EDIT If you do not want to use razor, I could suggest you to build anchors by your self like following

<a href="<%=Url.Action("ViewTopic", "Forum",new { id=item.topicId})%>" class="YourClass"> item.headerclob </a>

Upvotes: 2

Related Questions