views:

6131

answers:

4
<% using (Html.BeginForm() { %>

  <%=Html.DropDownList("TopItemsList", ViewData["ListData"], new { onchange="[???]" })%>

<% } %>

In the above example, what value should you set onchange to? Or, how do you get the correct form?

Is there any difference with Ajax.BeginFrom?

+11  A: 

try this:

<%=Html.DropDownList("TopItemsList", ViewData["ListData"], new { onchange="this.form.submit();" })%>

Every form element in the has a "form" property that is pointed to the form that contains this element.

Yes, using "Html." and "Ajax." has a difference. Ajax. means that partial page update will be used and the whole page will not be reloaded.

maxnk
Just to correct the statement,<%=Html.DropDownList("TopItemsList", ViewData["ListData"], new { @onchange="this.form.submit();" })%>note the @ symbol.
PieterG
A: 

That works.

I was using this.Form.submit()... and getting an object undefined error. Capitalization matters! :)

Thanks.

SO is not a forum
mgroves
A: 

This article could also help: http://laymensterm.blogspot.com/2008/12/mvc-dropdownlist.html

Completely unrelated and probably flawed information in that link.
aredkid
A: 

Why are you mixing your html with javascript??

Delete the onchange attribute and add some JQuery:

$("#TopItemsList").change(function () {

    $("input[type=submit]").click();

});
Lee Smith
Will cause issues if you have more than one submit input.
ThiefMaster