改修Home控制器,修改home的首页内容
- 但一开始就发现一个问题,系统不是自带有home控制器,也有home视图,可是F5,HOME是不能显示的。
- 这个太郁闷了,这个改Startup.cs 的时候,把路由功能删了,需要增加回来,
- 完整的Startup.cs 代码。 ``` using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using NewLife.Cube;
namespace dqltest { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; }
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews(); // 2020-12-26添加
services.AddCube();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCube(env);
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
- 然后会发现bootstrap未能正常引用,主要是他集的才址有变化,
- 于是更改这个模板页内容
- 同时需要增加静态文件的引用 app.UseStaticFiles();
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCube(env);
app.UseStaticFiles();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
布局页面
<!DOCTYPE html>
- 显示成功前台。
<a name="cvmsq"></a>
### 首页创建bootstrap tab来智能选择学科内容
前台页面代码
@{ ViewData[“Title”] = “Home Page”; }
随课练习
每课小练!
要点知识
每课小练!
</div>
<div class="tab-pane fade" id="ios">
<p>
1
</p>
</div>
<div class="tab-pane fade" id="jmeter">
<p>2</p>
</div>
<div class="tab-pane fade" id="ejb">
<p>
3。
</p>
</div>
</div>
- 样式

<a name="lrPI6"></a>
### 背单词之
- 单词有两种,一种是随及的,这个好理解,一个是按几年级第几节。
- 相来想读表再去重再检索,但这样感觉反而麻烦,实际是我没有找到,哈,
- 那么我们新建一个表专门管理章节
- models中新建表
增加一个区域菜单ChapterController,并在后台管理,增加英语的相关年级和单元信息<br />
- 后台控制器中读出年级和单元的所有表,因为是英语,所以皮配了为英语。
- 首先在model可增加一个前台显示的model,名为Chapterview;

- 代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace dqltest.Models
{
public class Chapterview
{
public string Grade { get; set; }
public string Unit { get; set; }
}
}
控制器中增加model.copy方法 ,到新的Chapterview模型,然后前台进行forecah
public IActionResult EnglishWord1()
{
var course = Chapter.FindAll(Chapter._.Subject.Contains(“英语”));var mmm= course.Select(s => { var m = new Chapterview(); m.Copy(s); return m; }).ToList(); return View(mmm); }
@model IList按章记录
@foreach(var level1 in Model.GroupBy(x => x.Grade)){@level1.Key 年级
foreach(var level2 in Model) { if(@level1.Key == level2.Grade) { @level2.Unit 单元 } } }效果<br />
<a name="bd5nn"></a>
### 按单元背单词之随及显示
- 这里要一条显示一页,所以要先用到分页和随及功能
- 就是随及抽这一单节的一个单词记录
- 后面我思考了一下,我即然是随及只读一条,为什么还要分页哩,每取一次读一次就OK拉。
- 用的mysql,SQL的写法:
SELECT * FROM englishwords
ORDER BY RAND()
LIMIT 1 ;
- 本来说有XCODE,但实在找不到,于是用SQL吧。
- 石头终于在线给了写法了
FindAll(where, “rand “, null, 0 ,1)
- 于是后台
public IActionResult ByCourseWords(string Grade,string Unit) { ///读出这个单节的所有内容
if (!String.IsNullOrEmpty(Grade)||String.IsNullOrEmpty(Unit))
{
var xxx = EnglishWords.FindAll(EnglishWords._.Grade.Contains(Grade)&EnglishWords._.Unit.Contains(Unit));
///直接妆使用sql,随及读出一条信息
var dal = DAL.Create("Membership");
var db = dal.Query("select * from EnglishWords ORDER BY RAND() LIMIT 1");
var list = EnglishWords.LoadData(db);
return View(list);
}
return View();
}
前台,注意送来的仍然是Ilist<>
@@model IList
努力吧~
@foreach (var item in Model) { }1 | 2 | 3 | 4 | |
---|---|---|---|---|
@item.Grade | @item.Word | @item.Explain | @item.Pronunciation | 详情 |
- 显示为一条记录拉

<a name="LrpTp"></a>
### 输入内容进行比较并操作
先进行页面设计,实现答案隐藏。
@@model IList
努力吧~
@@foreach (var item in Model) {@
@Model.Explain
@Model.Pronunciation
</div>
<hr />
<p>
<a class="btn btn-default btn-sm but" href="#" role="button">解析</a>
<label class="dqltile1" style="color:#0b8915;"> 共测:</label> @Model.TestNumbers 次,
<label class="dqltile1" style="color:#0b8915;"> 错误:</label> @Model.ErrorNumbers 次。
</p>
<div class="abc" style="display:none">
<p> <label class="dqltile1" style="color:#0b8915;"> 答案:</label> @Model.Word </p>
<p> <label class="dqltile1" style="color:#0b8915;"> 要点:</label> </p>
<p> @Model.MainPoints </p>
<p> <label class="dqltile1" style="color:#0b8915;"> 例名:</label> </p>
<p>
@if (@Model.ExampleSentence != null)
{ string[] arr = @Model.ExampleSentence.Split(';');
foreach (string s in arr)
{
<p>@s.ToString();</p>
}
}
</p>
<p> <label class="dqltile1" style="color:#0b8915;"> 短语搭配:</label> </p>
<p>
@if(@Model.WordsCollocation!=null)
{ string[] arr1 = @Model.WordsCollocation.Split(';');
foreach (string s in arr1)
{
<p>@s.ToString();</p>
}
} </p>
</div>
<div style="margin-bottom:70px;width:100%;"></div>
<a asp-action="Details" asp-route-id="@Model.ID">详情</a>
@}@
``` - 效果  - 实现访问一次,随及读出的时候,给该单词增加一个次数1 ``` ///对读出的这条信息返回并增加次数 if (list!=null) { list.TestNumbers += 1; list.Update(); return View(list); } ``` - 实现弹窗口 - [https://www.jq22.com/yanshi22162](https://www.jq22.com/yanshi22162) 使用的是这个,黑好用 - 前台 ``` @*@model IList努力吧~
@Model.Explain
@Model.Pronunciation
解析 @Model.TestNumbers 次, @Model.ErrorNumbers 次。
@*}*@ <!-- 消息弹窗 -->
<div class="sy-alert sy-alert-alert animated" sy-enter="zoomIn" sy-leave="zoomOut" sy-type="alert" sy-mask="true" id="alert2">
<div class="sy-title">测验结果</div>
<div class="sy-content" style=" display: none;
font-size: 1.5em;
color: #10b747;
padding: 10px;
“>非常正确,牛呀!!!