【发布时间】:2014-03-21 14:36:35
【问题描述】:
我的页面有两个按钮 Next 和 Previos。此按钮在 PartialView 中加载表格。 我的问题是当我第二次按下按钮时,它不起作用。
这里是代码
观点:
<div id="Centros">
<div class="divPantalla2">
<table cellspacing="0" class="table table-hover table-responsive table-bordered">
<tr>
<th class="thTablas">
Nombre
</th>
<th class="thTablas">
Nro- Establecimiento
</th>
<th class="thTablas">
Departamento
</th>
<th class="thTablas">
Localidad
</th>
<th class="thTablas">
</th>
</tr>
@if (ViewBag.OnePageOfCEProyecto != null)
{
foreach (ANEP.Models.CentroEducativoModel item in ViewBag.OnePageOfCEProyecto)
{
<tr>
<td>
@item.Nombre
</td>
<td>
@item.NroEstablecimiento
</td>
<td>
@if (item.dDepartamento != null)
{
@item.dDepartamento.Descripcion;
}
</td>
<td>
@if (item.dLocalidad != null)
{
@item.dLocalidad.NomLocalidad;
}
</td>
<td>
<button type="submit" value="Eliminar+@item.CEID" name="Command" class="btn_eliminar">
</button>
</td>
</tr>
}
}
</table>
</div>
<div id="botones">
@if (ViewBag.OnePageOfCEProyecto != null)
{
<div align="center">
<div align="center">
@if (Session["PROYECTO_PAGINA_ACTUAL"] != null && int.Parse(Session["PROYECTO_PAGINA_ACTUAL"].ToString()) > 1)
{
<button type="button" id="Primera" value="Primera1" name="Command" class="btn btn-primary">
<font color="#0C58A8"><<</font></button>
<button type="button" id="Anterior" value="Anterior1" name="Command" class="btn btn-primary">
<font color="#0C58A8"><</font></button>
}
<font color="#0C58A8">@int.Parse(Session["PROYECTO_PAGINA_ACTUAL"].ToString())</font>
@if (ViewBag.OnePageOfCEProyecto.Count == 8)
{
<button type="button" id="Siguiente" value="Siguiente1" name="Command" class="btn btn-primary">
<font color="#0C58A8">></font></button>
<button type="button" id="Ultima" value="Ultima1" name="Command" class="btn btn-primary">
<font color="#0C58A8">>></font></button>
}
</div>
</div>
}
</div>
</div>
部分视图:
<div class="divPantalla2">
<table cellspacing="0" class="table table-hover table-responsive table-bordered">
<tr>
<th class="thTablas">
Nombre
</th>
<th class="thTablas">
Nro- Establecimiento
</th>
<th class="thTablas">
Departamento
</th>
<th class="thTablas">
Localidad
</th>
<th class="thTablas">
</th>
</tr>
@if (ViewBag.OnePageOfCEProyecto != null)
{
foreach (ANEP.Models.CentroEducativoModel item in ViewBag.OnePageOfCEProyecto)
{
<tr>
<td>
@item.Nombre
</td>
<td>
@item.NroEstablecimiento
</td>
<td>
@if (item.dDepartamento != null)
{
@item.dDepartamento.Descripcion;
}
</td>
<td>
@if (item.dLocalidad != null)
{
@item.dLocalidad.NomLocalidad;
}
</td>
<td>
<button type="submit" value="Eliminar+@item.CEID" name="Command" class="btn_eliminar">
</button>
</td>
</tr>
}
}
</table>
</div>
<div id="botones">
@if (ViewBag.OnePageOfCEProyecto != null)
{
<div align="center">
<div align="center">
@if (Session["PROYECTO_PAGINA_ACTUAL"] != null && int.Parse(Session["PROYECTO_PAGINA_ACTUAL"].ToString()) > 1)
{
<button type="button" id="Primera" value="Primera1" name="Command" class="btn btn-primary">
<font color="#0C58A8"><<</font></button>
<button type="button" id="Anterior" value="Anterior1" name="Command" class="btn btn-primary">
<font color="#0C58A8"><</font></button>
}
<font color="#0C58A8">@int.Parse(Session["PROYECTO_PAGINA_ACTUAL"].ToString())</font>
@if (ViewBag.OnePageOfCEProyecto.Count == 8)
{
<button type="button" id="Siguiente" value="Siguiente1" name="Command" class="btn btn-primary">
<font color="#0C58A8">></font></button>
<button type="button" id="Ultima" value="Ultima1" name="Command" class="btn btn-primary">
<font color="#0C58A8">>></font></button>
}
</div>
</div>
}
</div>
AJAX 功能(仅用于按钮 next):
$(document).ready(function () {
$("#Siguiente").on("click", function () {
var accion = $('#Siguiente').val();
$.ajax({
url: "/Proyecto/TablaCentros",
type: "GET",
cache: false,
data: { command: accion }
})
.done(function (partialViewResult) {
$("#Centros").html(partialViewResult);
});
});
});
还有控制器:
public ActionResult TablaCentros(string command, Proyecto p)
{
if (command != null)
{
if (command.Contains("Siguiente1"))
{
if (Session["REGISTRO_PROYECTO"] != null)
{
Proyecto model = p;
int page = (int)Session["PROYECTO_PAGINA_ACTUAL"];
page++;
Session["PROYECTO_PAGINA_ACTUAL"] = page;
List<CentroEducativoModel> lista = (List<CentroEducativoModel>)Session["PROYECTO_CENTRO_EDUCATIVOS"];
var onePageOfCEProyecto = lista.ToPagedList(page, 8); // will only contain 15 products max because of the pageSize
ViewBag.OnePageOfCEProyecto = onePageOfCEProyecto;
cargarEstadoProyecto();
cargarCentroEducativos();
cargarClaseProyecto();
cargarTipoProyecto();
return PartialView("_TablaCentros", model);
}
}
}
return PartialView("_TablaCentros");
}
对不起我的英语,
谢谢!!!
【问题讨论】:
-
看起来你的观点和你的局部观点是一样的。是吗?
-
是的,因为我的页面第一次加载带有一些元素的表格,但是当您按下一步时,页面会加载带有不同数据的部分视图
-
如果是这种情况,那么我建议您将部分内容添加到您的页面中。这样一来,您只需将代码放在一个地方,避免重复。
标签: html ajax asp.net-mvc asp.net-mvc-4 partial-views