0

When I call the BeginForm ajax function, it does access the PartialView but instead of placing it in the target it refreshs the whole View placing only the code of the PartialView executed.

These are my scripts:

 bundles.Add(new ScriptBundle("~/bundles/superbundle").Include(
        "~/Scripts/jquery-{version}.js",
        "~/Scripts/jquery-ui-{version}.js",
        "~/Scripts/jquery.unobtrusive*",
        "~/Scripts/jquery.validate*",
        "~/Scripts/jquery.unobtrusive-ajax.js"));

This is my partialView _BusquedaDeSensores.cshtml

@model IEnumerable< Recnons.Models.GetSensorByClient_Result>


    @using (Ajax.BeginForm("EntradaSalida", "Home", new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "Post",  UpdateTargetId = "entradaSalida" }))
    { 
    <select id="Sensores" name="Sensores">
       @foreach (var item in Model)
       {
       <option value="@item.Id">@item.Id</option> 
       }
        </select>
       <input type="submit" value="submit" />
    }

This is my HomeController

    [HttpPost]
    public ActionResult BusquedaDeSensores(int identificador)
    {
        ViewBag.Message = "Siga los pasos para completar el proceso...";
        retail2Entities cl = new retail2Entities();

        List<GetSensorByClient_Result> sensores = cl.GetSensorByClient(identificador,0).ToList();
        return PartialView("_BusquedaDeSensores",sensores);

    }

Finally here is the part of my index where i try to use the ajax function

<ol class="round">
    <li class="one">

    @using (Ajax.BeginForm("BusquedaDeSensores", "Home", new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "Post", UpdateTargetId = "busquedaDeSensores" }))
    {

       <select id="identificador" name="identificador">
       @foreach (var item in Model)
       {
       <option value="@item.idClient">@item.name</option> 
       }
        </select>
       <input type="submit" value="submit" />


    }

    </li>

    <li id="busquedaDeSensores "class="two">

    </li>

    <li id="entradaSalida "class="three">

    </li>
</ol> 

I have been trying to fix this for hours, one thing i do is the use of diferent Models, The model of the first select shown is diferent that the one managed by the ActionResult BusquedaDeSensores.. is that ok?

jayms117
  • 63
  • 7
  • Whenever this happens it's usually because the scripts have not been loaded correctly -- here's the [minimal necessary for the Ajax.BeginForm](http://stackoverflow.com/questions/23895918/mvc5-ajax-beginform-and-the-correct-scripts-load-order/23897170#23897170). It looks like you may be double loading `jquery.unobtrusive-ajax.js` (the wildcard should have taken care of it). The partial view for your result does not need to have the same model as the form's model. – Jasen Jul 16 '15 at 23:17
  • Hi, thanks, I Added those scripts and updated my js, but still it doesnt work! – jayms117 Jul 17 '15 at 14:35
  • You have two `Ajax.BeginForm` -- which doesn't work? – Jasen Jul 17 '15 at 23:04

0 Answers0