0

This is my code in SearchResults View for the colours dropdownlist

<td>@Html.DropDownList("colours", TryCast(ViewData("colours"), SelectList),
                       New With {.onchange = "document.getElementById('wineSearchCriteria').submit();"})</td>

I've set the form name to 'wineSearchCriteria'

<form action="/Wines/SearchResults" method="post" name="wineSearchCriteria"
    input type="submit" value="Search"/>

but the form is not posting back when the colours dropdown is changed. I'm sure this will be something simple!

tereško
  • 58,060
  • 25
  • 98
  • 150
  • 2
    Just as a bit of info. A [postback](http://stackoverflow.com/questions/183254/what-is-a-postback/183481#183481) is very much a Webforms concept. MVC is more tightly coupled to HTTP so it's either a [POST](http://en.wikipedia.org/wiki/POST_(HTTP)) or a [GET](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods). – Liam Oct 24 '13 at 16:28

2 Answers2

1

document.getElementById() will only retrieve elements by their ID, but you are not assigning an ID to the form. You are assigning a name to the form. Use the id attribute instead:

<form action="/Wines/SearchResults" method="post" id="wineSearchCriteria"
input type="submit" value="Search"/>
Katie Kilian
  • 6,815
  • 5
  • 41
  • 64
0

You should set the id attribute as "wineSearchCriteria", not the name.

<form action="/Wines/SearchResults" method="post" id="wineSearchCriteria" />
WannaCSharp
  • 1,898
  • 2
  • 13
  • 19