Pergunta

Código:

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

Quando executo a página, recebo a ação correta do controlador para acionar com os dados corretos na coleção de formulários:

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 bem a partir de um ajax.actionlink como este:

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

Quando a postagem acontece, eu navegou para uma nova página em vez de permanecer na página existente e atualizar o conteúdo da div.

Obrigado.

Foi útil?

Solução

Submit () provavelmente não aciona ajax.beginform e, portanto, é processado como postagem de costume. Veja isso, por exemplo: Eventos jQuery adicionais enviando meu ajax.beginform. Alternativamente, adicione o botão Enviar (talvez oculto) e ligue para o seu .Click ().

Outras dicas

The using(Ajax.BeginForm(...)) doesn't work when it contains a Html.RenderPartial.

Does it works with Internet explorer 7. I have some issue with IE7 in cascading DropDownList. The Ajax.BeginForm doesn't retrieve form (Request.Form["myIdForm"] is blank) Value in IE7, in all others web browser it works (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 profileChanged action and return a partial view ("FilterContracts").

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top