asp.net-mvc - 将参数传递到局部 View 以用作操作链接中的查询字符串名称?

标签 asp.net-mvc partial-views actionlink

我正在尝试将此代码设为局部 View ,以便将 alpha 分页添加到我的网格中:

<div class="t-pager-wrapper" style="border-bottom:0">
        <div class="t-pager t-reset">                                
            @foreach (var letter in CollectionUtil.Alphabet){
                @Html.ActionLink(letter, "Index", new { Equipment_filter = "Equipment.Name~startswith~'" + letter + "'" }, new { @class = "t-link" })
            }
            @Html.ActionLink("All", "Index")                                                       
        </div>
    </div>

如何传入名称“Equipment”以用作查询字符串中的参数?我所有的网格都有自己的数据名称,因此为了使分页过滤器起作用,每个页面上的名称都会不同,Equipment_filter、Color_filter、Cars_filter 等。

因此示例 URL 为:

http://www.mydomain.com/Equipment?Equipment-filter=Equipment.Name~startswith~'B'
http://www.mydomain.com/Color?Color-filter=Color.Name~startswith~'C'

因此,我需要将参数传递给过滤器前缀的“设备”部分,以及用于进行对象属性比较的路径的“设备名称”。

编辑:

好吧,我只是通过在链接的 href 参数中使用 Url.Action 来做到这一点:

<a href="@Url.Action("index")?Equipment-filter=Equipment.Name~startswith~'@letter'">@letter</a>

此时提供“Equipment”和“Equipment.Name”是微不足道的,因为一切都是字符串。如果有人想使用 ActionLink 发布解决方案,我会将其标记为答案。

最佳答案

好吧,我只是通过在链接的 href 参数中使用 Url.Action 来做到这一点:

<a href="@Url.Action("index")?Equipment-filter=Equipment.Name~startswith~'@letter'">@letter</a>

此时提供“Equipment”和“Equipment.Name”是微不足道的,因为一切都是字符串。

关于asp.net-mvc - 将参数传递到局部 View 以用作操作链接中的查询字符串名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16176423/

相关文章:

c# - 如何让 Html.DropdownFor() 选择当前元素?

ruby-on-rails - rails prepend_view_path 可安装引擎

javascript - 在部分 View MVC 中使用 jquery/js

asp.net-mvc-2 - 带有 LinkText = 绝对 URL 的 ASP.NET MVC ActionLink

asp.net-mvc-3 - @Html.ActionLink 和 @Html.DisplayFor 同时(不对,但它描述了我想要做的事情)

html - MVC @html.Actionlink 包含 html i 标签

asp.net-mvc - asp.net mvc - 如何将用户返回到上一个操作?

css - 具有指定 HTML id 的 Html.ActionLink?

asp.net-mvc - Owin 如何在 Application_EndRequest 阶段之后设置 Asp.Net 身份验证 cookie?

asp.net-mvc - 如何在一个 View 中呈现强类型的局部 View ?