How do you submit a dropdownlist in asp.net mvc

Gene picture Gene · Dec 13, 2008 · Viewed 49.1k times · Source
<% 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?

Answer

maxnk picture maxnk · Dec 13, 2008

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.