I have a project that I am working on, it’s being developed in ASP.NET MVC2
Currently I have used Ajax to load some data. It works great on firefox and chrome however I have an issue with IE.
My controller:
public ActionResult UpdateSearchResults(FormCollection formValues)
{
var equipmentsResults = EquipmentQueries.GetEquipments(Request.Form["Voltage"],
Request.Form["EquipmentType"],
Request.Form["Word"]);
return PartialView("SearchResults", equipmentsResults);
}
My view:
<% using (Ajax.BeginForm("UpdateSearchResults",
new AjaxOptions {UpdateTargetId = "loadingData",
LoadingElementId = "loadingImage",
HttpMethod = "POST"}))
{ %>
<fieldset>
<legend>Filters</legend>
<label>Voltage: </label>
<%=Html.DropDownList("Voltage", (SelectList)ViewData["Voltage"], "Select Voltage", new { onchange = "this.form.submit();" })%>
<br />
<label>Equipment Type: </label>
<%=Html.DropDownList("EquipmentType", (SelectList)ViewData["Equipment"], "Select Equipment Type")%>
<br />
<label>Station Keyword Search: </label>
<%=Html.TextBox("Word")%>
<br />
<input id="btnSubmit" type="submit" value="Submit" name="submit" />
<br />
</fieldset>
<img id="loadingImage" src="../../Images/ajax-loader.gif" alt="loading"/>
<div id="loadingData"></div>
<% }%>
I have included the following scripts
<script src="../../Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
What I found during debugging is that in chrome and firefox all the DropDownList populate the Request.Form ( Request.Form(“Voltage”) actually displays what the user has picked on the DropDownList), however in IE this Request.Form doesn’t get populated at all, it’s just an empty string…
Thanks for the help everyone
While I have no clue why your code doesn’t work on IE I have some suggestions about improving it. So as usual we start by defining a view model which will represent the data we are dealing with on the view:
Model:
Controller:
View:
Now you can safely dump all the
MSAjax*scripts as well as allAjax.*helpers. Do it the proper way: unobtrusively, the jquery way.