Ajax.BeginForm UpdateTargetId not working with DropDownList

the code:

<% using (Ajax.BeginForm("GetResourcesByProject", "CreateRequest", new AjaxOptions { UpdateTargetId = "ResourceListDiv"})) { Response.Write(Html.DropDownList("SelectProject", Model.ProjectList, "Select Project", new { onchange = "this.form.submit();" })); } %> 

When I start the page, I get the correct controller action to start with the correct data in the form collection:

 public ActionResult GetResourcesByProject(FormCollection formCollection) { var resourceModels = (from project in POTSModel.ProjectList where project.Id == Convert.ToInt32(formCollection["SelectProject"]) select project).First().Resources; return PartialView("ResourceList", resourceModels); } 

It works great with Ajax.ActionLink as follows:

 <%= Ajax.ActionLink("Select", "GetResourcesByProject", "CreateRequest", new { projectId = item.Id }, new AjaxOptions { UpdateTargetId = "ResourceListDiv" })%> 

When a message occurs, I switch to a new page instead of staying on an existing page and updating the contents of the div.

Thanks.

+6
drop-down-menu asp.net-mvc ajax.beginform
source share
3 answers

submit () probably does not start Ajax.BeginForm, and therefore it is treated like a regular post. See For example: Additional jQuery events dispatching my Ajax.BeginForm . Alternatively add a submit button (possibly hidden) and call it .click ().

+5
source share

using(Ajax.BeginForm(...)) does not work when it contains Html.RenderPartial .

+1
source share

This works with Internet Explorer 7. I have a problem with IE7 in cascading DropDownList. Ajax.BeginForm does not retrieve the form (Request.Form ["myIdForm"] is empty) Value in IE7, it works in all other browsers (including IE8)!

  <% using (Ajax.BeginForm("profileChanged", "profiles", new AjaxOptions() { UpdateTargetId = "customer", OnComplete = "SetHiddenProfile" }, new { @class = "filtersForm" })) { %> <p id="customer"> <% Html.RenderPartial("FilterContracts"); %> </p> <%} %> 

I call the database to populate dropDown in the profileChanged action and return a partial view ("FilterContracts").

0
source share

All Articles