欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

View和View的参数传递

发布时间:2025/3/20 编程问答 33 豆豆
生活随笔 收集整理的这篇文章主要介绍了 View和View的参数传递 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

View和View的参数传递


          在做ITOO的过程中,遇到了一个问题,就是页面和页面之间跳转参数传递的问题。

          这里前台使用的是easyUI的组件,第一个页面查看考生登录情况,其中有一个详情,点击之后,会跳转到第二个页面。

          第二个页面需要第一个页面的一些参数,你所选的该行的各个参数,考试、考场、考试日期和时间等等,查询并显示该场考试,这个考场的考生详细信息。

          第一个页面


          第二个页面


          这里在第一个View中使用的js,通过调用Controller中的一个方法,把第一个页面中的参数传到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中写一个方法用来接收传递过来的参数,再返回到第二个页面,这里使用的是ViewData。

<span style="font-size:24px;">public ActionResult MonitoreDetails(){//从第一个页面得到相关的参数,传给第二个页面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;"><table id="Chapter1" title="考生登录情况" class="easyui-datagrid" style="width:1160px; height: 400px;" idfield="itemid" pagination="true" data-options="rownumbers:true,url:'/Monitore/QueryMonitoreDetails?ExamID=@ViewData["ExamID"]&ExamPlaceID=@ViewData["ExamPlaceID"]&StartDate=@ViewData["StartDate"]&StartTime=@ViewData["StartTime"]',pageSize:5, pageList:[10,20,30,40],method:'get',toolbar:'#tb',striped:true" fitcolumns="true"><thead><tr><th data-options="field:'StudentNo',width:100">学号</th><th data-options="field:'StudentName',width:100">姓名</th><th data-options="field:'State',width:100">状态</th>@*<th data-options="field:'IP',width:100">IP</th>*@<th data-options="field:'Colleage',width:100">学院</th><th data-options="field:'Major',width:100">专业</th></tr></thead></table> </span>


总结

以上是生活随笔为你收集整理的View和View的参数传递的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。