보기에서 다음 양식 사용MVC Ajax가 드롭 다운리스트 값을 게시하지 않습니다.
<% 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">
<%} %>
다음 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>
의 결과 및 내 컨트롤러의 코드로 값을 캐 내려고
public ActionResult PatientSearch(string patientType, int edCenterID) {
//do something with values
}
patientType is is 항상 ""(으)로 전달됩니다. 그러나 edCenterID는 게시되고 수신됩니다.
이것을 Ajax.BeginForm에서 HTML.BeginForm으로 변경하면 모든 것이 완벽하게 작동합니다.
내 컨트롤러 DropDownList에 문제가 있습니까?
코멘트에서 추가
@Eoin은 내 선택이 가치없는 렌더링이고 그것이 아마도 문제라고 지적했습니다.
1. 표준 게시물에서는 작동하지만 Ajax 게시물에서는 작동하지 않는 이유는 무엇입니까?
2. 목록이있는 값을 포함하도록 드롭 다운 목록을 가져 오는 방법은 간단한 문자열 전용 목록 (키 없음)입니다. 내 SelectList 아래에 생성하는 데 사용되는 코드를 게시 오전
ViewData["PatientTypeList"]=new SelectList(new List<string>()
{ "Referral", "Patient"});
patientType 값이 표시된 값과 같아야합니다. 누락 된 값 태그라고 생각했지만, 표준 제출과 ajax 제출이 아닌 이유는 무엇입니까? –
다음 코드로 SelectList를 만듭니다. ______ ViewData [ "PatientTypeList"] = new SelectList (new List() { "Referral", "Patient"})); ____ 이드가없는 목록에 더 좋은 방법이 있습니까? (필요한 경우 다른 질문으로 게시 해 드리겠습니다.) –
비교를 위해 'EdCenterList'를 정의하는 방법 –