0

我有一个显示表格和 DropDownList 的页面 - 它们不包含在表单中。当用户在 DropDownList 中选择一个值时,JavaSript 将所选值放入名为 selectedCategory 的文本框中,该文本框位于表单中:

@Html.TextBox("selectedCategory", null, new { @id = "selectedCategory", @style = "width: 100px;" })

我正在使用分页,所以我有:

@Html.PagedListPager(Model, page => Url.Action("Index",
new { page, SortO = ViewBag.SortO, 
      FilterV = ViewBag.FilterV, 
      category = selectedCategory  }))

在这种情况下,我收到错误: 当前上下文中不存在名称“selectedCategory”。 当我在页面源上没有“category = selectedCategory”运行时,我看到该字段存在:

<input id="selectedCategory" name="selectedCategory" style="width: 100px;" type="text" value="" />

所以我的问题是如何添加“category = selectedCategory 字段的值”?

谢谢,

zb

4

1 回答 1

0

我再次分析了我的问题并得出结论,我需要以不同的方式解决我的问题 - 使用会话变量或 ViewBag。

这就是为什么:代码:

@Html.PagedListPager(Model, page => Url.Action("Index",
new { page, SortO = ViewBag.SortO, 
      FilterV = ViewBag.FilterV, 
      category = xxx  }))

转换为 HTML:

<li><a href="/?page=2&SortO=My%20Sort&FilterV=My%20Filter&category=xxx">2</a></li>
  <li><a href="/?page=3&SortO=My%20Sort&FilterV=My%20Filter&category=xxx">3</a></li>
  <li><a href="/?page=4&SortO=My%20Sort&FilterV=My%20Filter&category=xxx">4</a></li> 

用户从 DropDownList 中选择一个选项后,JavaScript 函数将需要使用所选选项的值更新“category=xxx” - 我认为可以完成,但它看起来对我来说很复杂。

于 2015-02-11T15:26:49.260 回答