I have a dropdownlist in my asp.net MVC2 view like this:
<% using(Html.BeginForm("temp","Settings")){ %>
<%= Html.DropDownList("drpFields", new SelectList(Model.Fields, "FieldID", "NiceName", whiteout.FieldID))
}
%>
and I want to pass the dropdown selected value from view to controller action. How do I modify this:
<a class="icon-button-success" href='<%: Url.Action("EditWhiteOut", "Settings", new {FieldId = 1}) %>'>
<img src='<%: Url.Content("~/static/Images/update.png") %>' alt="Update" />
</a>
I want to pass dropdown’s selected value to FieldId.
If you’re willing to use Ajax, you can avoid the form if you want to use
jQuery.ajax. You might want to give your anchor a value for its ID property (my example below only uses its class attribute)But, since you want to do a regular postback, you’ll want to use another overload of
Html.BeginFormso you can specify an ID attribute for the form (I specified the parameter names in case you’re unfamiliar with this overload)And the jQuery used to make your link submit the form will create a standard submit. So, as long as your select list has a name attribute, it’s value will be included in the post’s payload.
If you wanted to do a redirect anyway (using the
$.ajaxmethod), you could always dowindow.location.href='redirect/link';inside thesuccessfunction in the$.ajaxcall