WCP.Mvc
8.0.0
dotnet add package WCP.Mvc --version 8.0.0
NuGet\Install-Package WCP.Mvc -Version 8.0.0
<PackageReference Include="WCP.Mvc" Version="8.0.0" />
<PackageVersion Include="WCP.Mvc" Version="8.0.0" />
<PackageReference Include="WCP.Mvc" />
paket add WCP.Mvc --version 8.0.0
#r "nuget: WCP.Mvc, 8.0.0"
#:package WCP.Mvc@8.0.0
#addin nuget:?package=WCP.Mvc&version=8.0.0
#tool nuget:?package=WCP.Mvc&version=8.0.0
WCP.Mvc
WCP.Mvc 是一组面向 ASP.NET Core MVC 的辅助组件,主要包含:
基于 TagHelper 的分页组件(Bootstrap 风格),通过
<pager>标签轻松输出分页导航;针对百度 UEditor 的集成扩展,提供
AddUEditorService注入与服务封装;一套简单的分页模型接口
IPagedList及其实现,方便在 MVC 中统一分页结果结构。Target Framework:
net8.0License:
Apache-2.0作者 / Author: 吴存平
安装 (Install)
在 NuGet 中搜索并安装:
- 包名:
WCP.Mvc
使用 .NET CLI:
dotnet add package WCP.Mvc
使用 Package Manager:
Install-Package WCP.Mvc
PackageReference 示例:
<ItemGroup>
<PackageReference Include="WCP.Mvc" Version="8.0.0" />
</ItemGroup>
分页组件 (PagerTagHelper)
命名空间:WCP.Mvc.TagHelpers
核心类型:
IPagedList/BasePagedList/StaticPagedList/PagedListMetaDataPagedListRenderOptions:分页渲染配置PagerTagHelper:<pager>标签助手
1. 注册 TagHelper
在 _ViewImports.cshtml 中添加:
@addTagHelper *, WCP.Mvc
2. 控制器中构造分页数据
using Microsoft.AspNetCore.Mvc;
using WCP.Mvc.TagHelpers;
public class UserController : Controller
{
public IActionResult Index(int page = 1)
{
const int pageSize = 10;
var allUsers = GetUsers(); // 你的数据源
var pagedList = new StaticPagedList<User>(
allUsers.Skip((page - 1) * pageSize).Take(pageSize),
page,
pageSize,
allUsers.Count
);
return View(pagedList);
}
}
3. 视图中使用 <pager>
@model WCP.Mvc.TagHelpers.IPagedList<User>
<table class="table">
</table>
<pager page-list="@Model"
page-param="page"
asp-action="Index"
asp-controller="User"
page-options="@PagedListRenderOptions.ClassicPlusFirstAndLast">
</pager>
PagerTagHelper 会根据 IPagedList 信息与 PagedListRenderOptions 的配置生成类似:
<nav>
<ul class="pagination">
</ul>
</nav>
你可以通过 PagedListRenderOptions 定制:
- 是否显示首页/上一页/下一页/末页
- 是否显示省略号
- 按钮文字格式、CSS 类名等
百度 UEditor 集成 (UEditorMvcExtension)
命名空间:WCP.Mvc.Editor
核心类型:
UEditorMvcExtension:提供AddUEditorService扩展方法UEditorService:编辑器请求处理服务Config:全局配置项(资源路径、配置文件路径等)
1. 注册编辑器服务
在 Program.cs 或 Startup.cs 中:
using WCP.Mvc.Editor;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
// 注册 UEditor 服务
builder.Services.AddUEditorService(
webPath: builder.Environment.ContentRootPath,
webUrl: "/",
configFileRelativePath: "ueditor.json",
isCacheConfig: true
);
var app = builder.Build();
2. 控制器中转发编辑器请求
using Microsoft.AspNetCore.Mvc;
using WCP.Mvc.Editor;
public class UEditorController : Controller
{
private readonly UEditorService _ueditorService;
public UEditorController(UEditorService ueditorService)
{
_ueditorService = ueditorService;
}
[HttpGet, HttpPost]
[Route("/ueditor/net/controller")]
public IActionResult UEditorHandler()
{
var response = _ueditorService.ProcessRequest(HttpContext);
return Content(response.Result, response.ContentType);
}
}
实际方法名与返回类型请以
UEditorService定义为准,上述仅为典型用法示例。
注意事项 (Notes)
- 使用分页 TagHelper 时,请确保视图模型实现了
IPagedList接口。 - TagHelper 默认使用 Bootstrap 风格类名(如
page-item、page-link),可通过PagedListRenderOptions自定义。 - 使用 UEditor 时,请确保静态资源、配置文件路径与前端引用保持一致,并做好上传安全校验(文件类型、大小等)。
License
本项目使用 Apache-2.0 许可证。详情请参阅 NuGet 包或源码中的 LICENSE 说明。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Http.Features (>= 5.0.8)
- Microsoft.AspNetCore.Mvc.ViewFeatures (>= 2.3.0)
- Microsoft.AspNetCore.Razor (>= 2.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.