MVC 页面表格,点击查看将一行的对象传入下一个页面

不使用强类型页面,在第一个页面上放表格,最后一列点击查看将本行对象传入。

        <table class="table table-bordered">
            <thead>
                <tr>
                    <th title="任务名称">任务名称</th>
                    <th title="执行用户">执行用户</th>
                    <th title="起始时间">起始时间</th>
                    <th title="结束时间">结束时间</th>
                    <th title="任务描述">任务描述</th>
                    <th title="操作">操作</th>
                </tr>
            </thead>
            <tbody>
                {{each Lsts }}
                <tr>
                    <td title="{{$value.TaskName}}">{{$value.TaskName}}</td>
                    <td title="{{$value.UserName}}">{{$value.UserName}}</td>
                    <td title="{{$value.StartTime}}">{{$value.StartTime}}</td>
                    <td title="{{$value.EndTime}}">{{$value.EndTime}}</td>
                    <td title="{{$value.TaskDescription}}">{{$value.TaskDescription}}</td>
                    <td title="">
                        <a onclick="detailClick({{$value}})">查看</a>
                    </td>
                </tr>
                {{/each }}
            </tbody>
        </table>

detailClick方法,打开新页面,将此对象转为json字符串传入下一页面。:

function detailClick(trrObj) {
    var jsonStr = JSON.stringify(trrObj);
    window.open("/TaskManager/TaskDataRecord/DataRecord?TaskRunRecordData=" + jsonStr);
}

第二个页面的控制器中存入该json字符串。

        public ActionResult DataRecord()
        {
            if (!Request.Params.AllKeys.Contains("TaskRunRecordData"))
            {
                Response.Status = "404 TaskRunRecordData Lost!";
                return new EmptyResult();
            }
            string _taskRunRecordData = Request.Params["TaskRunRecordData"];

            if (!string.IsNullOrEmpty(_taskRunRecordData))
            {              
                    ViewBag.TrrDataJsonStr = _taskRunRecordData;
                    return View();
            }
            else
            {
                Response.Status = "404 TaskRunRecordData Error!";
                return new EmptyResult();
            }
        }

第二个页面前端将此json字符串保存为去掉html标记的对象:

    <script type="text/javascript">
        var trrDataObj = @Html.Raw(@ViewBag.TrrDataJsonStr);
    </script>

页面中拿到了此对象,js中对该对象数据进行相关处理。

    var trr = trrDataObj;
    $("#writeTaskName").html(trr.TaskName);
    $("#writeUserName").html(trr.UserName);
    $("#writeStartTime").html(trr.StartTime);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值