【问题标题】:Access Html.ActionLink property in Controller file访问控制器文件中的 Html.ActionLink 属性
【发布时间】:2013-06-24 23:32:14
【问题描述】:

我需要访问我的控制器文件中的 practiceid 属性,请帮助我如何访问它

<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 参数中没有任何内容。

【问题讨论】:

    标签: asp.net-mvc-3 razor sitecore


    【解决方案1】:

    this question

    您要做的是将参数添加到标签,而不是链接。这意味着您应该将第四个参数保留为 null 并改用第五个。即。

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

    the documentation 用于此辅助方法,重点是第五个参数。

    【讨论】:

    • 没有成功。应用与上述相同的方法后,仍将 null 值作为在 action 和 Request 中指定的 Parameter 它给了我 null
    • 好的,您能检查一下 Model.SearchResultItems.Facets 是否包含您期望的数据吗? IE。将调试器连接到返回有问题视图的操作并查看 Facets 对象中的内容。
    【解决方案2】:

    添加额外的空值

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

    【讨论】:

    • 添加这个空值作为参数后没有成功
    猜你喜欢
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多