2015-02-10 156 views
0

我有一个页面显示一个表格和一个DropDownList - 它们不包含在表格中。 当用户选择在DropDownList的值 - JavaSript放在一个文本框中命名selectedCategory位于表单中的选定值:RAZOR - 如何使用Url.Action将数据传递给控制器​​?

@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'在当前上下文中不存在。 当我在网页来源上运行没有“类别= selectedCategory”我看到了场上存在:

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

所以我的问题是如何添加“类别= selectedCategory领域的价值”?

感谢,

ZB

回答

0

我再次分析了我的问题,我得出结论,我需要解决我的问题不同的方式 - 使用Session变量或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函数将需要更新“的范畴= xxx“与所选选项的值 - 我认为可以完成,但它看起来很复杂。

相关问题