冯 海

一个程序新人菜鸟的日记,希望大家多多关照。QQ:32316131

bootstrap adminlte教程11:打造内部邮件系统 -发件箱管理

发件和收件就一个样,为了方便,我弄成了二个视图,将index方法,复制改名,新建视图

 1.控制器

// GET: Emails
		public ActionResult SeedIndex(string emailState, string SearchString, int? page)
		{
			///初始化分页
			if (!string.IsNullOrEmpty(emailState) && !string.IsNullOrEmpty(SearchString))
			{
				page = 1;
			}
			//赋值回传
			ViewBag.emailState = emailState;
			ViewBag.SearchString = SearchString;
			//默认情况下是只显示未阅读的。同时按creattime降序
			string myusername = Session["username"].ToString();
			var emalilist = db.Emails.Where(c => c.EmailState == "0"&&c.CreatUser== myusername).OrderByDescending(z => z.CreatTime);
			//开始if进行分析
			if (!string.IsNullOrEmpty(emailState))     //这是不为空,表示点了已阅,需在搜索已阅
			{
				emalilist = db.Emails.Where(c => c.EmailState == "1" && c.CreatUser == myusername).OrderByDescending(z => z.CreatTime);

			}

			if (!string.IsNullOrEmpty(SearchString))  //表示有字段
			{

				emalilist = db.Emails.Where(c => c.Title.Contains(SearchString) && c.CreatUser == myusername).OrderByDescending(z => z.CreatTime);
			}


			int pageNumber = page ?? 1;
			int pageSize = 10;
			//通过ToPagedList扩展方法进行分页
			//IPagedList<CmsContent> pagedList = seachindex.ToPagedList(pageNumber, pageSize);


			return View(emalilist.ToPagedList(pageNumber, pageSize));



		}

  

 

2.视图

@model PagedList.IPagedList<jsdhh2.Models.Email>
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" />

@{
	ViewBag.Title = "Index";
}
<div class="dhhheight1 col-md-12 col-xs-12"></div>
<!--start 左 -->
<div class="col-md-3 hidden-xs">
	<div class="box box-solid">
		<div class="box-header with-border">
			<h3 class="box-title">内部邮箱</h3>

			<div class="box-tools">
				<button type="button" class="btn btn-box-tool" data-widget="collapse">
					<i class="fa fa-minus"></i>
				</button>
			</div>
		</div>
		<div class="box-body no-padding" style="display: block;">
			<ul class="nav nav-pills nav-stacked">
				<li class="active">
					<a href="~/Emails/Index">
						<i class="fa fa-inbox"></i> 收件箱
						<span class="label label-primary pull-right">12</span>
					</a>
				</li>
				<li><a href="#"><i class="fa fa-envelope-o"></i> 已发邮箱</a></li>
				<li><a href="~/Emails/Create"><i class="fa fa-file-text-o"></i> 发邮件</a></li>

			</ul>
		</div>
		<!-- /.box-body -->
	</div>



</div>

<!--start 右 -->
<div class="col-md-9 col-xs-12 pull-right">


	<!-- Content Header (Page header) -->
	<section class="content-header">

		<h1>
			邮件清单
			<small>请不要乱发邮件哟~</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
			<li class="active">Here</li>
		</ol>

	</section>
	<!--end Content Header (Page header) -->
	<!--start button -->
	<h2></h2>
	<div class="col-md-4 col-xs-6">

		@using (Html.BeginForm("SeedIndex", "Emails", new { @class = "form-inline" }, FormMethod.Post))
			{

			<div class="form-inline">

				<div class="form-group">
					<div class="input-group">
						@Html.TextBox("SearchString", "", new { @class = "form-control", @Style = "display:inline" })
						<span class="input-group-btn ">
							<input id="btnSearch" class="btn btn btn-primary" type="submit" value="搜索">
						</span>
					</div>
				</div>
			</div>
			}
	</div>
	<h2></h2>

	@using (Html.BeginForm("DelEmails", "Emails", new { @class = "form-inline" }, FormMethod.Post))
	{
		<div class="btn-group text-left col-md-8 col-xs-6" role="group" aria-label="...">

			<input type="submit" class="btn btn-warning" value="删除" />
			<a class="btn btn-default" href="/Emails/Index?emailState=1" role="button">已阅</a>

		</div>

		<div class="dhhheight1"></div>

		<h2> </h2>



		<table class="table  table-hover" style="table-layout:fixed">
			<tr>
				<th width="40px">
					<input id="selectAll" name="selectAll" type="checkbox" value="true" onclick="changeState(this.checked)" /><input name="selectAll" type="hidden" value="false" />

				</th>

				<th width="50%">
					标题
				</th>
				<th>
					发表时间
				</th>

				<th>
					收件人
				</th>



				<th></th>
			</tr>

			@foreach (var item in Model)
			{
				<tr>
					<td>

						@Html.CheckBox(item.Id, false)
					</td>
					<td style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">
						<small>
							@if (item.EmailState == "1")
							{ <span class="label label-success">阅</span>
							}
							else
							{<span class="label label-warning">未</span>
							}

						</small>		<a href="~/Emails/Details?id=@Html.DisplayFor(modelItem => item.Id)">@Html.DisplayFor(modelItem => item.Title)</a>
					</td>
					<td>
						@Html.DisplayFor(modelItem => item.CreatTime, "DateTimeTemplate")
					</td>

					<td>
						@Html.DisplayFor(modelItem => item.ReceiveUser)
					</td>
					<td>


						@Html.ActionLink("Del", "Delete", new { id = item.Id }, new { @class = "btn btn-warning btn-xs" })
					</td>
				</tr>
			}

		</table>




	}
	<hr />
	<!-- Main content -->
	Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
	@Html.PagedListPager(Model, page => Url.Action("SeedIndex",
  new { page, emailState = ViewBag.emailState, SearchString = ViewBag.SearchString }))


</div>



@section Scripts {
	<script type="text/javascript">
		function changeState(isChecked) {
			var chk_list = document.getElementsByTagName("input");
			for (var i = 0; i < chk_list.length; i++) {
				if (chk_list[i].type == "checkbox") {
					chk_list[i].checked = isChecked;
				}
			}
		}
	</script>
}

  

其他一样。

posted @ 2017-06-05 00:47  秋天来了哟  阅读(239)  评论(0编辑  收藏  举报
认识就是缘份,愿天下人都快乐!
QQ: 32316131
Email: 32316131@qq.com