asp.net core razor 一个页面,新增,列表,删除,修改等集大成操作
一、界面

二、razor代码
@page
@model xxtsoft.Web.Entry.Pages.sysadmins.stu.stu_bftz_addModel@{
Layout = "_LayoutAdminAdd";
ViewData["Title"] = "一生一档:就业帮扶台账";
}<style>
.table-responsive { width: 100%; overflow-x: auto;
} .table-responsive th, .table-responsive td{ white-space: nowrap;
}
</style><div class="layui-fluid">
<div class="layui-panel layui-padding-3">
<div class="table-responsive">
<h2>学生信息</h2>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="layui-table">
<tr>
<th colspan="7" class="layui-bg-blue">学生信息</th>
</tr>
<tr>
<th>学号</th>
<th>姓名</th>
<th>院系</th>
<th>专业</th>
<th>班级</th>
<th>手机号</th>
<th>生源地</th>
</tr>
<tr>
<td>@Model.Stu.xh</td>
<td>@Model.Stu.xm</td>
<td>@Model.Stu.yx</td>
<td>@Model.Stu.zy</td>
<td>@Model.Stu.bj</td>
<td>@Model.Stu.phone</td>
<td>@Model.Stu.sydsf</td>
</tr>
<tr>
<th colspan="4" style="text-align:center;" class="layui-bg-green">一生一档</th>
<th colspan="3" style="text-align:center;" class="layui-bg-green">省厅导入</th>
</tr>
<tr>
<th>是否困难生</th>
<th>就业意向</th>
<th>目前就业情况</th>
<th>预计就业时间</th>
<th>困难生类别</th>
<th>毕业去向</th>
<th>用人单位</th>
</tr>
<tr>
<td>@Model.Stu.sfkds <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-on="md">设置</a></td>
<td>@Model.Stu.jyyx</td>
<td>@Model.Stu.jyqk</td>
<td>@Model.Stu.yjjysj</td>
<td>@Model.Stu.kdslb</td>
<td>@Model.Stu.byqx</td>
<td>@Model.Stu.yrdw</td>
</tr>
</table>
</div>
</div>
<br />
<div class="layui-panel layui-padding-3">
<div class="table-responsive">
<h2>学生帮扶台账</h2>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="layui-table">
<thead>
<tr>
<th>序号</th>
<th>联系时间</th>
<th>联系人</th>
<th>帮扶方式</th>
<th>联系记录</th>
<th>操作</th>
</tr>
</thead>
<tbody>
@{ int i = 1;
}
@if (Model.BftzList.Count > 0)
{ foreach (var item in Model.BftzList)
{ <tr>
<td>@i</td>
<td>@item.lxsj</td>
<td>@item.lxr</td>
<td>@item.bffs</td>
<td>@item.lxjl</td>
<td>
<a href="stu_bftz_add?fst=@Model.fst&snd=@Model.snd&thd=@Model.thd&no=@Model.no&stuid=@item.stuid&bfid=@Common.SecurityHelper.DesEnc(item.id.ToString())">修改</a> <a href="stu_bftz_add?fst=@Model.fst&snd=@Model.snd&thd=@Model.thd&no=@Model.no&stuid=@item.stuid&bfid=@Common.SecurityHelper.DesEnc(item.id.ToString())&tpe=del">删除</a>
</td>
</tr>
i++;
}
} else
{ <tr>
<td colspan="4" style="text-align:center;">暂无联系记录</td>
</tr>
} </tbody>
</table>
</div>
</div>
<br />
<div class="layui-panel layui-padding-3">
<form class="layui-form" method="post" id="form1" lay-filter="form1">
<table class="layui-table tableform" width="100%">
<tr>
<td class="tip" width="120">目前就业情况:<font color="red">*</font></td>
<td>
<select name="jyqk" id="jyqk" asp-for="Stu.jyqk" lay-search="" lay-verify="required">
<option value="">请选择</option>
<option>签定就业协议形式就业</option>
<option>签劳动合同形式就业</option>
<option>其它录用形式就业</option>
<option>实习中</option>
<option>求职中</option>
<option>签约中</option>
<option>专升本</option>
<option>考公考编</option>
<option>暂不就业</option>
<option>境外留学</option>
<option>应征义务兵</option>
<option>自由职业</option>
<option>自主创业-创立公司</option>
<option>自主创业-个体工商户</option>
</select>
</td>
</tr>
<tr>
<td class="tip">联系时间<font color="red">*</font></td>
<td>
<div class="layui-input-wrap">
<div class="layui-input-prefix">
<i class="layui-icon layui-icon-date"></i>
</div>
<input type="text" name="lxsj" id="lxsj" asp-for="Stu_Bftz.lxsj" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")"lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
</div>
</td>
</tr>
<tr>
<td class="tip">联系人<font color="red">*</font></td>
<td>
<input type="text" name="lxr" id="lxr" asp-for="Stu_Bftz.lxr" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
</td>
</tr>
<tr>
<td class="tip">帮扶方式<font color="red">*</font></td>
<td>
<select lay-search="" lay-creatable="" name="bffs" id="bffs" asp-for="Stu_Bftz.bffs" lay-verify="required">
<option value="">请选择</option>
<option>信息推送</option>
<option>线上谈话/指导</option>
<option>线下谈话/指导</option>
<option>学业指导</option>
<option>物质帮扶</option>
</select>
</td>
</tr>
<tr>
<td class="tip">联系记录<font color="red">*</font></td>
<td>
<textarea placeholder="请输入联系内容" name="lxjl" asp-for="Stu_Bftz.lxjl" id="lxjl" lay-affix="clear" class="layui-textarea" lay-verify="required"></textarea>
</td>
</tr>
<tr>
<td class="tip"></td>
<td>
<input type="hidden" name="fst" id="fst" asp-for="fst">
<input type="hidden" name="snd" id="snd" asp-for="snd">
<input type="hidden" name="thd" id="thd" asp-for="thd">
<input type="hidden" name="no" id="no" asp-for="no">
<input type="hidden" name="stuid" id="stuid" asp-for="Stu.id">
<input type="hidden" name="bfid" id="bfid" asp-for="Stu_Bftz.id">
<input type="hidden" name="opid" id="opid" asp-for="loginSid">
<button class="layui-btn btn-block" lay-submit lay-filter="form1-submit">提交</button>
</td>
</tr>
</table>
</form>
</div></div><script>
layui.config({
base: '/layui/' // 静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use('index',function () { var $ = layui.$; var laydate = layui.laydate; var form = layui.form; var layer = layui.layer; var util = layui.util;
laydate.render({
elem: '#lxsj',
type: 'datetime',
fullPanel: true // 2.8+
});
util.on('lay-on', {
md: function () {
layer.open({
type: 2,
title: '设置',
area: ['100%', '100%'],
content: 'stu_bftz_add_md?fst=@Model.fst&snd=@Model.snd&thd=@Model.thd&no=@Model.no&stuid=@Model.id'
});
}
});
});</script>三、后端代码
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Security.Claims;
using System.Text;using xxtsoft.Application;
using xxtsoft.Common;using xxtsoft.Core;
namespace xxtsoft.Web.Entry.Pages.sysadmins.stu
{ //登录判断
[Authorize]
public class stu_bftz_addModel : PageModel
{
public string loginxm = "";//登录用户名
public string loginRole = "";//登录角色
public string loginSid = "";//登录id
public string GivenName = "";//真实姓名
[BindProperty] public Stu Stu { get; set; } = new();
[BindProperty] public Stu_Bftz Stu_Bftz { get; set; } = new();
public List<Stu_Bftz> BftzList { get; set; } = new(); // 属性绑定列表
[BindProperty] public string id { get; set; }
[BindProperty] public string fst { get; set; }
[BindProperty] public string snd { get; set; }
[BindProperty] public string thd { get; set; }
[BindProperty] public string no { get; set; }
private readonly SqlSugar.ISqlSugarClient _db;
public stu_bftz_addModel(SqlSugar.ISqlSugarClient db)
{
this._db = db;
}
public IActionResult OnGet()
{ #region 登录信息
loginxm = User.Identity.Name;
loginRole = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Role)?.Value;
loginSid = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid)?.Value;
GivenName = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.GivenName)?.Value;
#endregion
#region 权限判断
fst = CommHelper.FilerForm(Request.Query["fst"]);
snd = CommHelper.FilerForm(Request.Query["snd"]);
thd = CommHelper.FilerForm(Request.Query["thd"]);
no = CommHelper.FilerForm(Request.Query["no"]);
if (string.IsNullOrEmpty(fst) || string.IsNullOrEmpty(snd) || string.IsNullOrEmpty(no))
{ return MessageHelper.ShowPre("参数错误");
} var qx = ManageHelper.qx(fst, snd, thd, loginRole);
if (qx != "200")
{ return MessageHelper.ShowRedirect("无权限访问", "../desk/index");
} #endregion
#region 学生信息
id = CommHelper.FilerForm(Request.Query["stuid"]);
if (!string.IsNullOrEmpty(id))
{
Stu = _db.Queryable<Stu>().Where(it => it.id == int.Parse(id)).First();
BftzList = _db.Queryable<Stu_Bftz>()
.Where(x => x.stuid == int.Parse(id))
.OrderBy(x => x.cdt, SqlSugar.OrderByType.Desc)
.ToList();
} else
{ return MessageHelper.ShowPre("参数错误");
} #endregion
#region 帮扶信息 string bfid = CommHelper.FilerForm(Request.Query["bfid"]);
if (!string.IsNullOrEmpty(bfid))
{ bfid = SecurityHelper.DesDec(bfid); string tpe = CommHelper.FilerForm(Request.Query["tpe"]); if (tpe == "del")
{
_db.Ado.ExecuteCommand("delete from stu_bftz where id=" + int.Parse(bfid)); return Redirect("stu_bftz_add?fst=" + fst + "&snd=" + snd + "&thd=" + thd + "&no=" + no + "&stuid=" + id + "");
} else
{
Stu_Bftz = _db.Queryable<Stu_Bftz>().Where(it => it.id == int.Parse(bfid)).First();
}
} else
{
Stu_Bftz.lxr = GivenName;
} #endregion
return Page();
} public async Task<IActionResult> OnPost()
{
id = CommHelper.FilerForm(Request.Form["stuid"]); if (string.IsNullOrEmpty(id))
{ return Content("请输入必填项");
} await _db.Updateable(Stu).Where("id=" + id).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); string bfid = CommHelper.FilerForm(Request.Form["bfid"]);
Stu_Bftz.stuid = int.Parse(id); if (int.Parse(bfid) > 0)
{
string opid = CommHelper.FilerForm(Request.Form["opid"]);
Stu_Bftz.opid = int.Parse(opid);
Stu_Bftz.id = int.Parse(bfid); await _db.Updateable(Stu_Bftz).Where("id=" + bfid).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
} else
{ await _db.Insertable(Stu_Bftz).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
} return MessageHelper.ShowParentPre("操作成功");
}
}
}
