user2450960
user2450960

Reputation: 41

Access Html.ActionLink property in Controller file

I need to access practiceid property in my controller file please help how I can access this

<a href="" practiceid="df3d4335671b4fa880aebc2a6fc56869">Corporate</a>
<a href="" practiceid="26f4c9f5444b485c9d974f75361fa8ca">Tax &amp; Employee Comp/Exec Benefits</a>
<a href="" practiceid="40b0a3a0b2744fafae0475756693c37f">Business Finance &amp; Restructuring</a>

Regulatory

My csHtml code is as follows:

@foreach (var facetData in Model.SearchResultItems.Facets.Select((x) => new { Item = x.Key, Index = x.Value }))    
{
    <tr>
        <td>
           @Html.ActionLink(@facetData.Index, "Search","Search", new { practiceid = @facetData.Item })
        </td>
    </tr>
}

and controller code is as follows:

public ActionResult Search(string practiceid)
{

}

But I'm not getting anything in my practiceid parameter.

Upvotes: 0

Views: 391

Answers (2)

Szymon Kuzniak
Szymon Kuzniak

Reputation: 858

See this question.

What you want to do is to add parameters to the tag, not to the link. Which means you should leave fourth argument null and use fifth instead. ie.

@Html.ActionLink(@facetData.Index, "Search","Search", null, new { practiceid = facetData.Item })

And the documentation for this helper method with focus on fifth parameter.

Upvotes: 1

Kyle
Kyle

Reputation: 1172

Add the extra null

@foreach (var facetData in Model.SearchResultItems.Facets.Select((x) => new { Item = x.Key, Index = x.Value }))    
{
    <tr>
        <td>
           @Html.ActionLink(@facetData.Index, "Search","Search", new { practiceid = facetData.Item }, null)
        </td>
    </tr>
}

Upvotes: 0

Related Questions