完善Person页面的视图操作功能
经过上一篇,我们的person的权限已经正常加上了。那么我们回到我们的菜单类。给他重新加上权限。
这样的话,我们在启动页面的时候就不会看见联系人管理菜单了。只有登录后才可以看到菜单信息了。
添加控制器和视图
添加控制器
[AbpMvcAuthorize(PersonAppPermissions.Person)] public class PersonManageController : PhoneBookControllerBase { private readonly IPersonAppService _personAppService; public PersonManageController(IPersonAppService personAppService) { _personAppService = personAppService; } // GET: PersonManage public async System.Threading.Tasks.Task<ActionResult> Index(GetPersonInput input) { var output = await _personAppService.GetPagedPersonsAsync(input); return View(output); } }
控制器上也是做了权限判断的,还有就是将personservice注入到控制器中。
调用联系人查询信息,这里我们使用了异步调用
添加视图界面
@using Abp.Web.Mvc.Extensions @using YoYoCMS.PhoneBook @model Abp.Application.Services.Dto.PagedResultOutput<YoYoCMS.PhoneBook.Persons.Dtos.PersonListDto> @{ ViewBag.ActiveMenu = "Persons.Person"; ViewBag.Title = L("PersonHeaderInfo"); } @section scripts{ @Html.IncludeScript("~/Views/PersonManage/Index.js") } <div> <h1>@L("Person")</h1> <div class="row"> <div class="col-md-12"> <button data-toggle="modal" data-target="#PersonCreateModal" class="btn btn-primary pull-right"> <i class="fa fa-plus"></i> @L("CreatePerson")</button> <table class="table"> <thead> <tr> <th>@L("Name")</th> <th>@L("EmailAddress")</th> <th>@L("CreationTime")</th> </tr> </thead> <tbody> @foreach (var person in Model.Items) { <tr> <td>@person.Name </td> <td>@person.EmailAddress</td> <td>@person.CreationTime</td> </tr> } </tbody> </table> </div> </div> </div> <div class="modal fade" id="PersonCreateModal" tabindex="-1" role="dialog" aria-labelledby="PersonCreateModalLabel" data-backdrop="static"> <div class="modal-dialog" role="document"> <div class="modal-content"> <form name="tenantCreateForm" role="form" novalidate class="form-validation"> <div class="modal-header"> <h4 class="modal-title"> <span>@L("CreatePerson")</span> </h4> </div> <div class="modal-body"> <div class="form-group"> <label>@L("Name")</label> <input class="form-control" type="text" name="Name" required maxlength="@PhoneBookConsts.MaxNameLength" minlength="2"> </div> <div class="form-group"> <label>@L("EmailAddress")</label> <input class="form-control" type="email" name="EmailAddress" required maxlength="@PhoneBookConsts.MaxEmailAddressLength" minlength="2"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">@L("Cancel")</button> <button type="submit" class="btn btn-primary blue"> <i class="fa fa-save"></i> <span>@L("Save")</span> </button> </div> </form> </div> </div> </div>
然后是js代码
(function() { $(function() { var _personService = abp.services.app.person; var _$modal = $('#PersonCreateModal'); var _$form = _$modal.find("form"); _$form.validate(); _$form.find('button[type="submit"]').click(function (e) { e.preventDefault(); if (!_$form.valid()) { return; } var person = _$form.serializeFormToObject(); abp.ui.setBusy(_$modal); console.log(person); _personService.createPersonAsync(person).done(function () { _$modal.modal("hide"); location.reload(true); //reload page to see new person! }).always(function() { abp.ui.clearBusy(_$modal); }); }); _$modal.on('shown.bs.modal', function () { _$modal.find('input:not([type=hidden]):first').focus(); }); }); })();
然后运行项目
ok,就是正常实现了。添加person功能
那么我们的删除、修改功能怎么做呢。空了我在更新。
为了方便和大家交流我建立了几个群,欢迎大家加群交流哦~
-
【52ABP .NET CORE 实战交流】:633751348
-
【ASP.NetCore Mvc EF入门学习】: 104390185
-
【ABP代码生成器交流群】104390185:
-
【ABP架构设计交流群4】726578484:
作者:梁桐铭(52ABP:基于DDD强大稳定的WEB应用框架! )
出处:http://www.cnblogs.com/wer-ltm
本作品由角落的白板报
创作,采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
欢迎转载,但任何转载必须保留完整文章,在显要地方显示署名以及原文链接。如您有任何疑问或者授权方面的协商,请
加群沟通留言。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?