2013-06-20 100 views
0

我需要在我的控制文件訪問practiceid財產,請幫助我如何可以訪問此訪問Html.ActionLink財產

<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> 

監管

我CSHTML代碼如下:

@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> 
} 

和控制器的代碼如下:

public ActionResult Search(string practiceid) 
{ 

} 

但我沒有得到任何在我的practiceid參數中的任何東西。

回答

0

添加額外的空

@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> 
} 
+0

將此空值作爲參數添加後沒有成功 – user2450960

1

this question

你想要做的是將參數添加到標籤,而不是鏈接。這意味着你應該讓第四個參數爲空,並使用第五個參數。即。

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

而且the documentation與專注於第五個參數這個輔助方法。

+0

沒有成功。應用上面提到的同樣仍然獲得作爲參數中指定的null值作爲參數,以及在請求它給了我空 – user2450960

+0

好吧,你可以檢查Model.SearchResultItems.Facets是否包含你期望的數據? IE瀏覽器。將調試器連接到返回有問題的視圖並查看Facets對象中的內容的操作。 –