冯 海

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

bootstrap adminlte教程8:问答系统的ClubContents的新建页面

1.控制器

现在这个水平就不需要再写说明了。

ViewBag.drolistmenu = (db.CmsColumns.Where(x => x.ColumnType=="2")).Select(g => new SelectListItem

  上面的这一句,在GET中,ColumnType==2是我在栏目管理那这样分类的,Tpye=1为CMS的栏目,为2则是这个问答的栏目。

 

     public ActionResult Create()
        {
			///取栏目type=2的所有栏目
			ViewBag.drolistmenu = (db.CmsColumns.Where(x => x.ColumnType=="2")).Select(g => new SelectListItem
			{
				Text = g.Name,
				Value = g.Id.ToString(),
				Selected = false
			});




			return View();
        }

        // POST: ClubContents/Create
        // 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关 
        // 详细信息,请参阅 https://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
		[ValidateInput(false)]
		public async Task<ActionResult> Create([Bind(Include = "Id,CreatTime,EditTime,ColumnId,Title,Contents,CreatUser,ReplyID,PcIp,ReplyCount,ClubPermission,ClubState,ClubOerder")] ClubContent clubContent)
        {
			var dt = DateTime.Now;
			string str = dt.ToString("yyyyMMddHHmmss");
			clubContent.Id = str;                                     //生成ID。
			clubContent.CreatTime = DateTime.Now;
			clubContent.EditTime = DateTime.Now;
			clubContent.ReplyCount = 0;
			clubContent.ClubOerder = 0;                         //排序,到是降序排列,为了后期可以管理员在上面点一下增加多少数值。
			clubContent.ClubState = "0";                        //为0表示未完结,为1表示已完结。
			clubContent.PcIp = Request.UserHostAddress;
			clubContent.CreatUser = Session["username"].ToString();
			clubContent.ClubHeadPic = Session["headerPic"].ToString();
			 

			if (ModelState.IsValid)
            {
                db.ClubContents.Add(clubContent);
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            return View(clubContent);
        }

  2.视图

@model jsdhh2.Models.ClubContent

@{
    ViewBag.Title = "Create";
}

	<!-- 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) -->

<section class="content">
	<div class="btn-group" role="group" aria-label="...">

		<a class="btn btn-success" href="~/ClubContents" role="button">返回列表</a>
	</div>
	<hr />


	@using (Html.BeginForm())
	{
		@Html.AntiForgeryToken()

		@Html.ValidationSummary(true, "", new { @class = "text-danger" })

			<div class="form-group">

				<div class="input-group">
					<div class="input-group-addon">选择栏目</div><span style="margin-left:10px;">
						@Html.DropDownList("ColumnId", new SelectList(ViewBag.drolistmenu, "Value", "Text"), "请选择")
						@Html.ValidationMessageFor(model => model.ColumnId, "", new { @class = "text-danger" })
					</span>
				</div>
			</div>

			<div class="form-group">

				<div class="input-group">
					<div class="input-group-addon">标 题</div>
					@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
					@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })

				</div>
			</div>
 


		  

			<div class="form-group">

				@Html.TextAreaFor(model => model.Contents, htmlAttributes: new { @id = "neirong", Value = "输入内容" })
 
					@Html.ValidationMessageFor(model => model.Contents, "", new { @class = "text-danger" })
			 
			</div>

		  
		 






		 

				 
				<div class="form-group left">
					
					<div class="col-md-12 left">
						<div class="checkbox">
							<label>
								@Html.DropDownListFor(m => m.ClubPermission, new List<SelectListItem>()
	   {
		   new SelectListItem() { Text= "公开", Value = "1" },
		   new SelectListItem() { Text= "不公开", Value = "0" },

	   })
							</label>
						</div>
						<input type="submit" value="表发" class="btn btn-primary" />
					</div>
				</div>
		 
	}
</section>

	@section Scripts {

	<script type="text/javascript">

		var editor = UE.getEditor('neirong', {
			//这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
			toolbars: [['FullScreen', 'Undo', 'Unlink', 'Redo', 'Link', 'Simpleupload', 'Emotion', 'Unlink', 'Attachment', 'Bold', 'underline', 'forecolor', 'backcolor', 'fontsize', 'justifyleft', 'justifycenter']],
			//focus时自动清空初始化时的内容
			autoClearinitialContent: true,
			//关闭字数统计
			wordCount: false,
			//关闭elementPath
			elementPathEnabled: false,
			//默认的编辑区域高度
			initialFrameHeight: 150,
			//更多其他参数,请参考ueditor.config.js中的配置项
			maximumWords: 500
		});
	</script>



	}
 

  

 

3.效果图

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