我正在尝试将此代码设为局部 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/