2013-06-20 76 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对象中的内容的操作。 –