当我调用BeginForm ajax函数时,它会访问PartialView,但不会将其放在目标中,而是刷新整个View,只放置PartialView的代码。
这些是我的脚本:
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"));
这是我的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" />
}
这是我的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);
}
最后,这是我的索引的一部分,我尝试使用ajax函数
<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>
我一直试图解决这个问题几个小时,我做的一件事就是使用不同的模型,所显示的第一个选择的模型与ActionResult BusquedaDeSensores管理的模型不同,是吗?