游戏BOSS提示系统- BOSS列表展示1
这是最终的效果页面,也是最复杂的地方了。下面一步一步的实现。
一、布局中顶部菜单的更改
1.布局页面代码
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - 我的Boss</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("My-Boss", "Index", "bossLists", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="~/BossLists/Create"><span>新建BOSS</span></a></li>
<li><a href="~/BossClasses1/"> <span>分类管理</span></a></li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
效果如下

二、BOSSList页面的上部菜单
动态取bossclass分类表中的数据

1.后台代码
///读出所有的BOSS分类,在前台进行搜索检引。 ViewBag.drolistmenu = db.BossClasses;
2.前台代码
<div class="col-md-12 col-sm-12 col-xs-12 padding bosstitleclass" style="display: block;">
<ul class="nav nav-pills nav-stacked">
@foreach (stboss.Models.BossClass data1 in (ViewBag.drolistmenu as IEnumerable<stboss.Models.BossClass>
))
{
<li>
<a href="~/bossLists/Index?Id=@data1.Id"><span class="glyphicon glyphicon glyphicon-th-large" aria-hidden="true"></span>
@data1.ClassName</a>
</li>
}
</ul>
</div>
三、新增BOSS-Create的设置。
1.对BOSS分类的下拉菜单进行GET方法读取出来,然后在前台CREATE中选择进去
新Create的后台代码
// GET: bossLists/Create
public ActionResult Create()
{
///读出所有的BOSS分类,以下拉框的形式写入。
ViewBag.drolistmenu = (db.BossClasses).Select(g => new SelectListItem
{
Text = g.ClassName,
Value = g.Id,
Selected = false
});
return View();
}
// POST: bossLists/Create
// 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关
// 详细信息,请参阅 https://go.microsoft.com/fwlink/?LinkId=317598。
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "Id,ColumnId,BossClass,BossName,updatetime,thistime,Adress")] bossList bossList)
{
string string1 = Request["exampleInputName2"];
string string2 = ConfigurationManager.AppSettings["myString"].Trim();
if (string1 != string2)
{
return RedirectToAction("ViewError");
}
if (ModelState.IsValid)
{
//var dt = DateTime.Now;
//string str = dt.ToString("yyyyMMddHHmmss");
bossList.thistime = DateTime.Now;
db.bossLists.Add(bossList);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(bossList);
}
前台代码:
@model stboss.Models.bossList
@{
ViewBag.Title = "Create";
}
<p>
<span class="titleh2">新建Boss</span>
@Html.ActionLink("返回", "Index", "", new { @class = "btn btn-success" })
</p>
<h2></h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.BossClass, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("BossClass", new SelectList(ViewBag.drolistmenu, "Value", "Text"), "请选择")
@*@Html.EditorFor(model => model.BossClass, new { htmlAttributes = new { @class = "form-control" } })*@
@Html.ValidationMessageFor(model => model.BossClass, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.BossName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.BossName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BossName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.updatetime, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.updatetime, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.updatetime, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Adress, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Adress, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Adress, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<label for="exampleInputName2" class="control-label col-md-2">验证字符</label>
<div class="col-md-10">
<input type="text" class="form-control" id="exampleInputName2" name="exampleInputName2">
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
三、手动刷新时间(EDit)
这节主要是刷新出错了,你用来效正,我按距现在还有多少分钟刷,手动输入分钟,他自动加上现在的时间,等于刷新时间来解决。
1.前台
在输入还距分钟刷的input中,使用JS来控制只能便宜正整数。很方便的
@model stboss.Models.bossList
@{
ViewBag.Title = "Edit";
}
<p>
<span class="titleh2">手动修改</span>
@Html.ActionLink("返回", "Index", "", new { @class = "btn btn-success" })
</p>
<h2></h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.BossName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.BossName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BossName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<label for="exampleInputName2" class="control-label col-md-2">还有多少分钟刷?</label>
<div class="col-md-10">
<input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
class="form-control" id="exampleInputName22" name="exampleInputName22">
</div>
</div>
<div class="form-group">
<label for="exampleInputName2" class="control-label col-md-2">验证字符</label>
<div class="col-md-10">
<input type="text" class="form-control" id="exampleInputName2" name="exampleInputName2">
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
2.后台。
// POST: bossLists/Edit/5
// 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关
// 详细信息,请参阅 https://go.microsoft.com/fwlink/?LinkId=317598。
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Edit([Bind(Include = "Id,ColumnId,BossClass,BossName,updatetime,thistime,Adress")] bossList bossList)
{
string string1 = Request["exampleInputName2"];
string string2 = ConfigurationManager.AppSettings["myString"].Trim();
if (string1 != string2)
{
return RedirectToAction("ViewError");
}
if (ModelState.IsValid)
{
///现在时间加上输入的分钟,等于最新的BOSS刷新时间
int xxx = Convert.ToInt32(Request["exampleInputName22"]);
bossList.thistime = DateTime.Now.AddMinutes(xxx);
db.Entry(bossList).State = EntityState.Modified;
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(bossList);
}
成品图

未完,下篇接着
浙公网安备 33010602011771号