在使用ajax局部刷新后 视图中的列表没有发生改变

baidu_22578859 2016-03-11 10:34:32
控制器代码
public ActionResult BoothShow(string strwhere)
{
string where;
if (strwhere == null)
{
strwhere = "";
where = string.Format("Name like '%{0}%'", strwhere);
}
else
{
where = string.Format("BusinessscopeID={0}", strwhere);
}
BLL.boothshow bll = new BLL.boothshow();
List<Model.boothshow> lst = bll.GetModelList(where);
AjaxList();
return View(lst);
}
public JsonResult AjaxList()
{
BLL.t_businessscope bll = new BLL.t_businessscope();
string str = "1=1";
List<Model.t_businessscope> a = bll.GetModelList(str);
ViewBag.list = a;
return Json(a);

}

视图中的部分代码
@foreach (var item in Model)
{
<tr style="text-align:center;">
<td>
@Html.DisplayFor(modelItem => item.BoothId)
</td>
<td>
@Html.DisplayFor(modelItem => item.VendorName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Phone)
</td>
<td>
@Html.DisplayFor(modelItem => item.Level)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location)
</td>
</tr>
}

<script>
$(".choice").click(function () {
$('#myModal').modal('hide');//点击后隐藏模态框
var text = $(this).children("a").attr("title");
var a = "全部";
var b = this.innerText;
//var c = b.substring(0, 2);

$(".myurl").text("选择类别");
$(".myurl").append("->" + b);

//ajax刷新
if (a == this.innerText) //点击全部,参数为空
{
var str=""
$.ajax({
type: "GET",
url: "/BoothShow/BoothShow",
data: { "strwhere": str },
/* success: function (msg) {
window.location.reload();
}*/
});
}
else { //点击某个菜单项,传入参数为对应点击的ID
$.ajax({
type: "GET",
url: "/BoothShow/BoothShow",
data: { "strwhere": text },

/* success: function (msg) {
alert("aaaa");
window.location.reload();
}*/
});
}
});
</script>
现在的问题是参数已经传进去了,但列表页面依然是所有数据。
具体如下:当点击id=choice的元素后能够得到新的数据放入lst并进入视图view,在调试过程中能看到Model的个数发生了变化。但在网页上的列表数据个数没有发生变化。
...全文
286 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
parlmes 2016-03-11
  • 打赏
  • 举报
回复
ViewBag.list 这里的 foreach (var item in Model) 应该写成 foreach (var item in ViewBag.list as Model.t_businessscope )
小涂 2016-03-11
  • 打赏
  • 举报
回复
同意一楼的,请按照一楼的方法修改试一下,看下结果
全栈极简 2016-03-11
  • 打赏
  • 举报
回复
你把/* success: function (msg) { alert("aaaa"); window.location.reload(); }*/ 这部分回调函数注释掉了,当然没有反应。 关于ajax的基本操作,看下这里:http://blog.csdn.net/chinacsharper/article/details/9748639

17,741

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧