0

I have page which display a table and a DropDownList - which are not included in the form. When a user selects a value in the DropDownList - JavaSript puts the selected value in a text box named selectedCategory which is located in a form:

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

I am using paging, so I have:

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

In this case I am getting error: The name 'selectedCategory' does not exist in the current context. When I run without "category = selectedCategory " on the page source I see the field exists:

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

So my question is how to add "category = value of selectedCategory field" ?

Thanks,

zb

Zalek Bloom
  • 551
  • 6
  • 13

1 Answers1

0

I analysed my problem again and I come to conclusion that I need to solve my problem different way - using Session variables or ViewBag.

And here is why: The code:

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

is converted to 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> 

After user selects an option from the DropDownList, a JavaScript function will need to update "category=xxx" with value of the selected option - I think it can be done, but it looks to convoluted to me.

Zalek Bloom
  • 551
  • 6
  • 13