Using the following form in a view
<% using (Ajax.BeginForm("PatientSearch", new {}, new AjaxOptions()
{
HttpMethod = "POST",
UpdateTargetId = "searchResults",
OnBegin = "BeginRequest",
OnSuccess = "SuccessRequest",
OnFailure = "FailRequest"
}))
{ %>
<%=Html.DropDownList("patientType",(SelectList)ViewData["PatientTypeList"]) %>
<%=Html.DropDownList("edCenterID",(SelectList)ViewData["EdCenterList"]) %><br />
<input type="submit">
<%} %>
Results in the following HTML
<select id="patientType" name="patientType">
<option selected="selected">Referral</option>
<option>Patient</option>
</select>
<select id="edCenterID" name="edCenterID">
<option value="2">Barren River District Health Department</option>
<option value="3">Madison County Health Department</option>
</select>
and I attempt to catch the values with the code in the my controller
public ActionResult PatientSearch(string patientType, int edCenterID) {
//do something with values
}
patientType is always passed as ""; however, edCenterID is posted and received just fine.
If I change this from an Ajax.BeginForm to an HTML.BeginForm, everything works perfectly.
Is the problem in my DropDownList, my controller, both?
ADDED FROM COMMENTS
@Eoin pointed out to me that my select is rendering without a value and that is probably the problem. That brings up two questions:
1. Why does it work with the a standard post, but not an Ajax post.
2. How do I get my dropdownlist to contain a value with the list is a simple string only list (no key). I am posting the code used to generate my SelectList below
ViewData["PatientTypeList"]=new SelectList(new List<string>()
{ "Referral", "Patient"});