大致要实现的 效果如下

1,添加Controller(用到的X.PagedList 注意到nuget添加)

using System.Web.Mvc;
using Abp.Application.Services.Dto;
using Abp.Runtime.Caching;
using Abp.Threading;
using Abp.Web.Mvc.Authorization;
using AutoMapper;
using LearningMpaAbp.Notifications;
using LearningMpaAbp.Tasks;
using LearningMpaAbp.Tasks.Dtos;
using LearningMpaAbp.Users;
using LearningMpaAbp.Users.Dto;
using LearningMpaAbp.Web.Models.Tasks;
using X.PagedList; namespace LearningMpaAbp.Web.Controllers
{
[AbpMvcAuthorize]
public class TasksController : LearningMpaAbpControllerBase
{
private readonly ITaskAppService _taskAppService;
private readonly IUserAppService _userAppService;
private readonly INotificationAppService _notificationAppService;
private readonly ICacheManager _cacheManager; public TasksController(ITaskAppService taskAppService, IUserAppService userAppService, ICacheManager cacheManager, INotificationAppService notificationAppService)
{
_taskAppService = taskAppService;
_userAppService = userAppService;
_cacheManager = cacheManager;
_notificationAppService = notificationAppService;
} public ActionResult Index(GetTasksInput input)
{
var output = _taskAppService.GetTasks(input); var model = new IndexViewModel(output.Tasks)
{
SelectedTaskState = input.State
};
return View(model);
} // GET: Tasks
public ActionResult PagedList(int? page)
{
//每页行数
var pageSize = 5;
var pageNumber = page ?? 1; //第几页 var filter = new GetTasksInput
{
SkipCount = (pageNumber - 1) * pageSize, //忽略个数
MaxResultCount = pageSize
};
var result = _taskAppService.GetPagedTasks(filter); //已经在应用服务层手动完成了分页逻辑,所以需手动构造分页结果
var onePageOfTasks = new StaticPagedList<TaskDto>(result.Items, pageNumber, pageSize, result.TotalCount);
//将分页结果放入ViewBag供View使用
ViewBag.OnePageOfTasks = onePageOfTasks; return View();
} public PartialViewResult GetList(GetTasksInput input)
{
var output = _taskAppService.GetTasks(input);
return PartialView("_List", output.Tasks);
} /// <summary>
/// 获取创建任务分部视图
/// 该方法使用ICacheManager进行缓存,在WebModule中配置缓存过期时间为10mins
/// </summary>
/// <returns></returns>
public PartialViewResult RemoteCreate()
{
//1.1 注释该段代码,使用下面缓存的方式
//var userList = _userAppService.GetUsers(); //1.2 同步调用异步解决方案(最新Abp创建的模板项目已经去掉该同步方法,所以可以通过下面这种方式获取用户列表)
//var userList = AsyncHelper.RunSync(() => _userAppService.GetUsersAsync()); //1.3 缓存版本
var userList = _cacheManager.GetCache("ControllerCache").Get("AllUsers", () => _userAppService.GetUsers()); //1.4 转换为泛型版本
//var userList = _cacheManager.GetCache("ControllerCache").AsTyped<string, ListResultDto<UserListDto>>().Get("AllUsers", () => _userAppService.GetUsers()); //1.5 泛型缓存版本
//var userList = _cacheManager.GetCache<string, ListResultDto<UserListDto>>("ControllerCache").Get("AllUsers", () => _userAppService.GetUsers()); ViewBag.AssignedPersonId = new SelectList(userList.Items, "Id", "Name");
return PartialView("_CreateTaskPartial");
} /// <summary>
/// 获取创建任务分部视图(子视图)
/// 该方法使用[OutputCache]进行缓存,缓存过期时间为2mins
/// </summary>
/// <returns></returns>
[ChildActionOnly]
[OutputCache(Duration = 1200, VaryByParam = "none")]
public PartialViewResult Create()
{
var userList = _userAppService.GetUsers();
ViewBag.AssignedPersonId = new SelectList(userList.Items, "Id", "Name");
return PartialView("_CreateTask");
} // POST: Tasks/Create
// 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关
// 详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=317598。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CreateTaskInput task)
{
var id = _taskAppService.CreateTask(task); var input = new GetTasksInput();
var output = _taskAppService.GetTasks(input); return PartialView("_List", output.Tasks);
} // GET: Tasks/Edit/5 public PartialViewResult Edit(int id)
{
var task = _taskAppService.GetTaskById(id); var updateTaskDto = Mapper.Map<UpdateTaskInput>(task); var userList = _userAppService.GetUsers();
ViewBag.AssignedPersonId = new SelectList(userList.Items, "Id", "Name", updateTaskDto.AssignedPersonId); return PartialView("_EditTask", updateTaskDto);
} // POST: Tasks/Edit/5
// 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关
// 详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=317598。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(UpdateTaskInput updateTaskDto)
{
_taskAppService.UpdateTask(updateTaskDto); var input = new GetTasksInput();
var output = _taskAppService.GetTasks(input); return PartialView("_List", output.Tasks);
} public ActionResult NotifyUser()
{
_notificationAppService.NotificationUsersWhoHaveOpenTask();
return new EmptyResult();
}
}
}

2,视图

@using Abp.Web.Mvc.Extensions
@model LearningMpaAbp.Web.Models.Tasks.IndexViewModel @{
ViewBag.Title = L("TaskList");
ViewBag.ActiveMenu = "TaskList"; //Matches with the menu name in SimpleTaskAppNavigationProvider to highlight the menu item
}
@section scripts{
@Html.IncludeScript("~/Views/Tasks/index.js");
}
<h2>
@L("TaskList") <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#add">Create Task</button> <a class="btn btn-primary" data-toggle="modal" href="@Url.Action("RemoteCreate")" data-target="#modal" role="button">(Create Task)使用Remote方式调用Modal进行展现</a> <a class="btn btn-success" href="@Url.Action("PagedList")" role="button">分页展示</a> <button type="button" class="btn btn-info" onclick="notifyUser();">通知未完成任务的用户</button>
<!--任务清单按照状态过滤的下拉框-->
<span class="pull-right">
@Html.DropDownListFor(
model => model.SelectedTaskState,
Model.GetTaskStateSelectListItems(),
new
{
@class = "form-control select2",
id = "TaskStateCombobox"
})
</span>
</h2> <!--任务清单展示-->
<div class="row" id="taskList">
@{ Html.RenderPartial("_List", Model.Tasks); }
</div> <!--通过初始加载页面的时候提前将创建任务模态框加载进来-->
@Html.Action("Create") <!--编辑任务模态框通过ajax动态填充到此div中-->
<div id="edit"> </div> <!--Remote方式弹出创建任务模态框-->
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="createTask" data-backdrop="static">
<div class="modal-dialog" role="document">
<div class="modal-content"> </div>
</div>
</div>

另外还有_createTaskPartial,_EditTaskPartial 等,这里就不贴代码了

以上。。。

参考http://www.jianshu.com/p/620c20fa511b

代码地址https://github.com/tianxiangd/LearnAbp

ABP学习入门系列(五)(展示实现增删改查)的更多相关文章

  1. JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(一)

    前言:出于某种原因,需要学习下Knockout.js,这个组件很早前听说过,但一直没尝试使用,这两天学习了下,觉得它真心不错,双向绑定的机制简直太爽了.今天打算结合bootstrapTable和Kno ...

  2. JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(四):自定义T4模板快速生成页面

    前言:上篇介绍了下ko增删改查的封装,确实节省了大量的js代码.博主是一个喜欢偷懒的人,总觉得这些基础的增删改查效果能不能通过一个什么工具直接生成页面效果,啥代码都不用写了,那该多爽.于是研究了下T4 ...

  3. JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(二)

    前言:上篇 JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(一) 介绍了下knockout.js的一些基础用法,由于篇幅的关系,所以只能分成两篇,望见谅!昨天就 ...

  4. SQLite 入门教程(四)增删改查,有讲究 (转)

    转于: SQLite 入门教程(四)增删改查,有讲究 一.插入数据 INSERT INTO 表(列...) VALUES(值...) 根据前面几篇的内容,我们可以很轻送的创建一个数据表,并向其中插入一 ...

  5. JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(三):两个Viewmodel搞定增删改查

    前言:之前博主分享过knockoutJS和BootstrapTable的一些基础用法,都是写基础应用,根本谈不上封装,仅仅是避免了html控件的取值和赋值,远远没有将MVVM的精妙展现出来.最近项目打 ...

  6. MVC3+EF4.1学习系列(二)-------基础的增删改查和持久对象的生命周期变化

    上篇文章中 我们已经创建了EF4.1基于code first的例子  有了数据库 并初始化了一些数据  今天这里写基础的增删改查和持久对象的生命周期变化 学习下原文先把运行好的原图贴来上~~ 一.创建 ...

  7. SQL Server学习之路(五):“增删改查”之“改”

    0.目录 1.前言 2.通过SSMS修改数据 3.通过SQL语句修改数据 3.1 修改单列数据 3.2 修改多列数据 1.前言 增删改查都是对数据的操作,其中"改"对应的SQL语句 ...

  8. MongoDB入门(介绍、安装、增删改查)

    文章作者公众号bigsai,已收录在回车课堂,如有帮助还请不吝啬点个赞赞支持一下! 课程导学 大家好我是bigsai,我们都学过数据库,但你可能更熟悉关系(型)数据库例如MySQL,SQL SERVE ...

  9. SQLite 入门教程(四)增删改查,有讲究

    增删改查操作,其中增删改操作被称为数据操作语言 DML,相对来说简单一点. 查操作相对来说复杂一点,涉及到很多子句,所以这篇先讲增删改操作,以例子为主,后面再讲查操作. 一.插入数据 INSERT I ...

  10. hibernate系列笔记(1)---Hibernate增删改查

    Hibernate增删改查 1.首先我们要知道什么是Hibernate Hibernate是一个轻量级的ORMapping对象.主要用来实现Java和数据库表之间的映射,除此之外还提供数据查询和数据获 ...

随机推荐

  1. jquery批量控制表单元素

    网上查了很久,避免下次再遇到相同的问题,记录一下: $("form input").prop("readonly", true); $("form i ...

  2. C# Linq 学习笔记

    刚刚学习了 Siki老师 的C#教程Linq部分,以下是笔记 需要引用命名空间 using System.Linq; 然后我们需要准备数据 武林高手类 /// <summary> /// ...

  3. .net core获取服务器本地IP及Request访问端口

    string str = (Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + ":" + ...

  4. 深入浅出“跨视图粒度计算”--3、EXCLUDE表达式

    本文由  网易云发布. 深入嵌入“跨视图粒度计算”的前面两篇分别讲了 1.理解数据的粒度 2.INCLUDE表达式 这一篇讲一下EXCLUDE表达式的用法. EXCLUDE,中文译为“排除”,顾名思义 ...

  5. 学习《精通数据科学从线性回归到深度学习》PDF+代码分析

    数据科学内容广泛,涉及到统计分析.机器学习以及计算机科学三方面的知识和技能.学习数据科学,推荐学习<精通数据科学从线性回归到深度学习>. 针对技术书籍,最好的阅读方法是对照每一章的示例代码 ...

  6. 《Python绝技:运用Python成为顶级黑客》 用Python进行无线网络攻击

    本章大部分代码都是实现了但是缺乏相应的应用环境,想具体测试的可以直接找到对应的环境或者自行修改脚本以适应生活常用的环境. 1.搭建无线网络攻击环境: 用Scapy测试无线网卡的嗅探功能: 插入无线网卡 ...

  7. hdoj1435 Stable Match(稳定婚姻问题)

    简单稳定婚姻问题. 题目描述不够全面,当距离相同时容量大的优先选择. 稳定婚姻问题不存在无解情况. #include<iostream> #include<cstring> # ...

  8. linux中 ll 和ls 区别

    ll 列出来的结果详细,有时间,是否可读写等信息 ,象windows里的 详细信息ls 只列出文件名或目录名 就象windows里的  列表 ll -t 是降序,  ll -t | tac 是升序 l ...

  9. Java Web之Servlet中response、request乱码问题解决

    Java Web之Servlet中response.request乱码问题解决   一.request请求参数出现的乱码问题 get请求: get请求的参数是在url后面提交过来的,也就是在请求行中, ...

  10. mysql中授权其它电脑链接指令。

    grant all privileges on yourDatabaseName to 'user'@'databaseIPAddress' identified by 'password' with ...