View和View的参数传递二
在做ITOO的时候,有一个需求,就是考生登录情况的模糊查询功能,用到了第一个页面中的参数,但是,这里的模糊查询事件是在第二个页面中触发的。
解决办法
首先,第一个页面在跳转到第二个页面的时候,进行参数的传递,把用到的参数传递给Controller,然后,使用ViewData从Controller返回到第二个页面。
第一个页面
<span style="font-size:24px;"><script type="text/javascript">
//在"操作"一列中添加超链接.-编辑考核项目
function rowformater(value, row, index) {
return '<a href="/Monitore/MonitoreDetails?ExamID=' + row.ExamID + '&ExamPlaceID=' + row.ExamPlaceID + '&StartDate=' + row.StartDate + '&StartTime=' + row.StartTime + '">详情</a>'
return;
}
</script></span>
Controller
<span style="font-size:24px;">public ActionResult MonitoreDetails()
{
//从监测界面拿到相关信息,查询具体学生信息-赵寒-2016-5-7
string ExamID = Request.QueryString["ExamID"];
string ExamPlaceID = Request.QueryString["ExamPlaceID"];
string StartDate = Request.QueryString["StartDate"];
string StartTime = Request.QueryString["StartTime"];
ViewData["ExamID"] = ExamID;
ViewData["ExamPlaceID"] = ExamPlaceID;
ViewData["StartDate"] = StartDate;
ViewData["StartTime"] = StartTime;
return View();
}</span>
在第二页面中,使用隐藏的控件来接收这些参数。
<span style="font-size:24px;"><input id="ExamID" value=@ViewData["ExamID"] hidden />
<input id="ExamPlaceID" value=@ViewData["ExamPlaceID"] hidden />
<input id="StartDate" value=@ViewData["StartDate"] hidden />
<input id="StartTime" value=@ViewData["StartTime"] hidden /></span>
此时,这些参数就有了,使用js进行模糊查询的时候,直接使用即可。
<span style="font-size:24px;"><script>
@*模糊查询的js——刘少锋——2016-8-3 15:55:29*@
function doSearch(value, name) {
var ExamID = $('#ExamID').val();
var ExamPlaceID = $('#ExamPlaceID').val();
var StartDate = $('#StartDate').val();
var StartTime = $('#StartTime').val();
$('#Chapter1').datagrid({
url: '/Monitore/FuzzyQueryStudentInfo?strLike=' + value + "&ExamID=" + ExamID + "&ExamPlaceID=" + ExamPlaceID + "&StartDate=" + StartDate + "&StartTime=" + StartTime
});
$("#Chapter1").datagrid("reload");//重新加载表信息datagrid
}
</script></span>