2009-10-21 16 views
6

Código:Ajax.BeginForm UpdateTargetId no funciona con DropDownList

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

Cuando ejecuto la página consigo la acción del controlador correcta para disparar con los datos correctos de la colección formulario:

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); 
} 

funciona bien desde un Ajax.ActionLink así:

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

Cuando el puesto sucede que estoy navegado a una nueva página en lugar o Permanecer en la página existente y actualizar los contenidos del div.

Gracias.

Respuesta

5

submit() probablemente no active Ajax.BeginForm, por lo que se procesa como la publicación habitual. Vea esto por ejemplo: Additional jQuery events submitting my Ajax.BeginForm. O bien agregue el botón de enviar (quizás oculto) y llame a su .click().

+1

El botón de envío oculta funciona perfectamente: \t \t \t <% usando (Ajax.BeginForm ("GetResourcesByProject", "createRequest", nuevos AjaxOptions {UpdateTargetId = "ResourceListDiv"})) \t \t \t \t { \t \t \t \t \t Response.Write (Html.DropDownList ("SelectProject", Model.ProjectList, "Seleccionar proyecto", nuevo {onchange = "document.getElementById ('projectSubmit'). Click();"})); \t \t tipo \t \t \t%> \t \t \t \t \t \t \t \t \t \t <% \t \t \t \t}% > Un poco feo y anticuado, pero funciona. Lamentablemente, la forma normal.submit() no golpea la forma ajax. Gracias por la ayuda. – Tyler

0

Funciona con Internet Explorer 7. Tengo algún problema con IE7 en cascada DropDownList. El Ajax.BeginForm no recupera el formulario (Request.Form ["myIdForm"] está en blanco) Valor en IE7, en todos los demás navegador web funciona (¡incluido IE8)!

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

que llame a la base de datos para poblar desplegable en la acción profileChanged y devolver una vista parcial ("FilterContracts").

1

El using(Ajax.BeginForm(...)) no funciona cuando contiene un Html.RenderPartial.

Cuestiones relacionadas