Asp.net MVC Ajax未发布dropdownlist值

Asp.net MVC Ajax未发布dropdownlist值,asp.net,asp.net-mvc,Asp.net,Asp.net Mvc,在视图中使用以下表单 <% using (Ajax.BeginForm("PatientSearch", new {}, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "searchResults", OnBegin = "BeginRequest", OnSuccess = "S

在视图中使用以下表单

<% 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">
<%} %>
patientType始终作为“”传递;但是,edCenterID的发布和接收情况良好

如果我将它从Ajax.BeginForm更改为HTML.BeginForm,那么一切都会完美运行

我的下拉列表和控制器都有问题吗

从评论中添加

@Eoin向我指出,我的select渲染时没有值,这可能就是问题所在。这就引出了两个问题:
1.为什么它可以和标准帖子一起工作,而不能和Ajax帖子一起工作。
2.如何让我的dropdownlist包含一个值,该列表是一个简单的纯字符串列表(无键)。我在下面发布用于生成我的SelectList的代码

ViewData["PatientTypeList"]=new SelectList(new List<string>() 
        { "Referral", "Patient"});
ViewData[“PatientTypeList”]=new SelectList(new List())
{“转诊”、“患者”});

患者类型列表是否有.Value

从外观上看,没有为PatientType DDL
呈现
值,因此基本上每个选项都有一个值=“因此实际上是回发正确的值

问题在于首先渲染的是什么

编辑

试一试

Dictionary d=newdictionary();
d、 添加(“转介”、“转介”);
d、 添加(“患者”、“患者”);
ViewData[“PatientTypeList”]=新的选择列表(d,“键”,“值”);

没有解决方案吗?似乎Ajax表单提交中出现了一些问题

这是一个很好的解决方案,请按常规编写方法,然后运行:

 function addDropDownValues() {
            $("select option").each(function(i) {
                if ($(this).text() == "Red") { $(this).attr('value', "Red"); }
                else if ($(this).text() == "Amber") { $(this).attr('value', "Amber"); }
                else if ($(this).text() == "Green") { $(this).attr('value', "Green"); }
                else if ($(this).text() == "Complete") { $(this).attr('value', "Complete"); }
             });
        }
其中“红色”、“琥珀色”等。。。是要传递的值

这将在每个下拉列表中附加一个值,生成:

<select name="status1" id="status1"><option value="Red">Red</option>
<option value="Amber">Amber</option>
<option selected="selected" value="Green">Green</option>
<option value="Complete">Complete</option>
</select>
红色
琥珀色
绿色
完成

这将适用于Firefox和Internet Explorer。Internet Explorer需要值项,firefox不需要。

patientType值应该与显示的值相同,我认为这是缺少的值标记,但为什么它可以与标准submit而不是ajax submit一起使用?我使用以下代码创建SelectList:\uuuuuuuuuuuuuuuu\ViewData[“PatientTypeList”]=new SelectList(新列表(){“转诊”、“患者”});____;没有id的列表有更好的方法吗?(如果需要,我会将此作为另一个问题发布。感谢您迄今为止的帮助!如何定义您的
EdCenterList
进行比较?通过编辑将此信息添加到原始问题中可能会更好。enterlist是从数据库中提取的,并且有一个键。我认为这就是为什么它有值的原因。_uuu新选择列表(new EdCenterRepository()).getAlledCenter(1),“ID”,“EdCenterName”);u uu\getAlledCenter函数只进行一个Linq2SQL调用,并返回一个IQueryable列表
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("referral", "referral");
d.Add("patient", "patient");

ViewData["PatientTypeList"]=new SelectList(d, "Key", "Value");
 function addDropDownValues() {
            $("select option").each(function(i) {
                if ($(this).text() == "Red") { $(this).attr('value', "Red"); }
                else if ($(this).text() == "Amber") { $(this).attr('value', "Amber"); }
                else if ($(this).text() == "Green") { $(this).attr('value', "Green"); }
                else if ($(this).text() == "Complete") { $(this).attr('value', "Complete"); }
             });
        }
<select name="status1" id="status1"><option value="Red">Red</option>
<option value="Amber">Amber</option>
<option selected="selected" value="Green">Green</option>
<option value="Complete">Complete</option>
</select>