View和View的参数传递
生活随笔
收集整理的這篇文章主要介紹了
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的参数传递的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CSS设置图片的重复
- 下一篇: View和View的参数传递二