Ajax.Beginform returning Partialview as View

Asked

Viewed 481 times

2

Goodnight!
I’m working on a Bed Management project.
In a particular View, I am displaying the registered Wards, and for filtering purposes, a field where one can research by the name of the Department to which certain(s) ward(s) belongs(at).
As shown below:

Botão de Pesquisa
For this, I am using the ajax Helper Ajax.BeginForm to return a Partialview and popular the table. The problem is that I am getting a separate view only with the data. I have already searched here on the site, some people had the same problem and included Unobtrusive in _Layout, but I have already done this. I’ve checked everything over and over, and I can’t identify what’s going on.

  • In Web.config is already set to Unobtrusive for True
  • I have already included the package validate. Unobtrusive
  • Since _Layout does not load Unobtrusive, I already made this correction.
  • My controller is equipped with Action Partialviewresult

In Sick Bay I have:

[HttpPost]
[ValidateAntiForgeryToken]
public PartialViewResult IndexDep(string pesquisa)
{
    return PartialView((_enfermariaAppService.ObterPeloNomeDoDepartamento(pesquisa)));
}

In Index (the image above) I have the following code:

//AjaxOptions
@{   
    var ajaxOpts = new AjaxOptions
    {        
        UpdateTargetId = "tbBody",
        HttpMethod = "Post",    
    };
}
//Formulário 
@using (Ajax.BeginForm("IndexDep", ajaxOpts))
{
   @Html.AntiForgeryToken()
   <div class="form-inline">
       @Html.TextBox("pesquisa","", new { @class = "form-control", @placeholder="Pesquise pela sigla do departamento" })
       <input type="submit" value="Pesquisar" class="btn btn-info" />
   </div>      
}
//Tabela onde deveria ser repassado a partialView
<table class="table table-bordered">
    <thead>
        //Cabeçalhos...
    </thead>
    <tbody id="tbBody">
        //Linhas...
    </tbody>

From now on, I would like to thank everyone who can collaborate.
Hug.

1 answer

2


Okay, according to your comment that clarified my doubt, you need to add also the jquery.unobtrusive-ajax.

Just look for Microsoft.jQuery.Unobstusive.Ajax for Nuget or in the Package Manager Console and add to the project.

Then add to your View that contains the helper Ajax.BeginForm as it did with the jQuery Validate Unobtrusive.

  • jquery.unobtrusive-ajax.js is not the same as jquery.validate.unobtrusive.min.js? Or I’m making a horrible mess.

  • They are not the same thing no. One is for validation, the other is necessary for the Ajax.BeginForm.

  • There was associate that both were equal, but in different versions. Thank you very much friend. I had already searched in four literatures and did not realize this my confusion. Grateful. Hugs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.