ITOO——MVC中View与Controller间的传值

    这几天在做ITOO5.0的时候时遇到了很多问题,也真的成长了很多。首先先说一下,我现在做的是基础的专业选修课模块。

    这里,我遇到了一个问题:当前界面名为:QueryChooseCourseResult,我点击上课班名称,想要跳转到该上课班学生详情界面(ChooseCourseStuInfo)。

    

   

    一开始觉得特别简单,不就传一个OnClassID的问题吗。后来发现里面大有玄机呀!

    先来看看我是怎么实现的。

首先是一个JS:

<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>//格式化标题字符串,并可以跳转到选修课学生信息界面,并且传onClassID到地址栏
        function titleFormat(value, row, index) {
            return "<a href=\"/QueryChooseCourseResult/ChooseCourseStuInfo?onClassID=" + row.onClassID + "\" >" + value + "</a>"
        }</strong></span>
这样,我在点击上课班名称时,就会出现以下效果:

    

这样,我们就把onClassID传到了地址栏。那么选课学生信息界面如何获取地址栏里的值呢?

首先,我们在Controller中的ChooseCourseStuInfo的加载界面的同时获取onClassID。要知道,MVC先加载Controller下的View().

<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>        #region 显示查询选课学生界面-王孟梅-2016年3月23日14:09:47
        public ActionResult ChooseCourseStuInfo()
        {
            ViewData["onClassID"] = Request.QueryString["onClassID"];
            return View();
        }
        #endregion</strong></span>
这样我们就把onClassID从地址栏传到了View里。

接下来,我们我们写了一个加载EasyUI表格的方法。

<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong><table id="dg" class="easyui-datagrid" title="选课学生信息" style="width: 700px; height: auto" data-options="<span style="color:#ff0000;"><span style="color:#ff0000;">url:'/QueryChooseCourseResult/QueryOnClassStudentByID?<span style="background-color: rgb(255, 255, 102);">onClassID=@ViewData["onClassID"]</span>'</span></span>"></span>
        <thead>
            <tr>
                <th data-options="field:'Name',width:200,align:'center'">姓名</th>
                <th data-options="field:'StudentNo',width:300,align:'center'">学号</th>
                <th data-options="field:'Sex',width:200,align:'center'">性别</th>
                @*<th data-options="field:'onClassID',width:200,align:'center'">上课班id</th>*@
            </tr>
        </thead>
    </table></strong></span>

样式神马的,忽略就好啦。要注意的是标记的这一句。这一句是在调用Controller中相应的查询方法,并且把onClassID传给了Controller。

这样,我们就可以完成了View与Controller之间的数据传递。

多多了解一下View与Controller之间的传递吧,做项目中会常用的!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 38
    评论
评论 38
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值