欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

MVC+EasyUI+三层新闻网站建立 详情页面制作方法(八)

时间:2021-05-06 09:41:08|栏目:.NET代码|点击:

 MVC新闻网站建立,完成详情页面的制作。

详情就是点击详情后弹出一个div,所以需要现在boby里面先建立一个div

<div id="detailDiv">
  <table>
   <tr>
    <td>标题:</td>
    <td><input class="easyui-textbox" style="width:250px;height:32px" id="title"/></td>
   </tr>
   <tr>
    <td>作者:</td>
    <td><input class="easyui-textbox" style="width: 250px; height: 32px" id="author" /></td>
   </tr>
   <tr>
    <td>发布日期:</td>
    <td><input class="easyui-textbox" style="width: 250px; height: 32px" id="subDateTime" /></td>
   </tr>
   <tr>
    <td>内容:</td>
    <td><input class="easyui-textbox" data-options="multiline:true" style="width: 400px; height: 250px" id="Msg" /></td>
   </tr>
  </table>
 </div>

这个div是需要隐藏的,当点击详情再弹出来。(隐藏语句需要放在页面加载的函数中)

//设置详细框为不可见
$("#detailDiv").css("display", "none");

在上一篇的datagrid里面我给详情的超链接添加了一个   onclick="showDetail('+row.Id+')"  事件    row.Id就是拿到点击的新闻Id

现在就需要完善这个方法

 //显示新闻详情
  function showDetail(index) {
   //弹出div
   $("#detailDiv").css("display", "block");
   $.post("/NewInfo/ShowModelById", { id: index }, function (data) {
    
    $("#title").textbox("setValue", data.Title);
    $("#author").textbox("setValue", data.Author);
    $("#subDateTime").textbox("setValue", ChangeDateFormat(data.SubDateTime));
    $("#Msg").textbox("setValue", data.Msg);
   });
   //弹出dialog
   $("#detailDiv").dialog({
    title: "新闻详情",
    modal: true,
    width: 500,
    height: 500,
    
   });
  }

同样的这里要根据Id查询新闻信息

在DAL层的NewInfoDal中

/// <summary>
  /// 根据id查询出记录
  /// </summary>
  /// <param name="id"></param>
  /// <returns></returns>
  public NewInfo GetEntityModel(int id)
  {
   string sql = "select * from T_News where Id=@Id";
   DataTable da = SqlHelper.ExcuteDataTable(sql, CommandType.Text, new SqlParameter("@Id", id));
   NewInfo newInfo = null;
   if (da.Rows.Count > 0)
   {
    newInfo = new NewInfo();
    LoadEntity(da.Rows[0], newInfo);
   }
   return newInfo;

  }

在BLL层的NewInfoServices中

 /// <summary>
  /// 根据id查询记录
  /// </summary>
  /// <param name="id"></param>
  /// <returns></returns>
  public NewInfo GetEntityModel(int id)
  {
   return NewInfoDal.GetEntityModel(id);
  }

最后在NewInfo控制器下建立ShowModelById方法

 /// <summary>
  /// 根据id查询记录
  /// </summary>
  /// <returns></returns>
  public ActionResult ShowModelById()
  {
   int id = int.Parse(Request["id"]);
   NewInfo model = NewInfoBll.GetEntityModel(id);
   return Json(model, JsonRequestBehavior.AllowGet);
  }

上一篇:轻松学习C#的String类

栏    目:.NET代码

下一篇:C#中this的使用实例分析

本文标题:MVC+EasyUI+三层新闻网站建立 详情页面制作方法(八)

本文地址:http://www.codeinn.net/misctech/115818.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有