WCP.Mvc 8.0.0

dotnet add package WCP.Mvc --version 8.0.0
                    
NuGet\Install-Package WCP.Mvc -Version 8.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WCP.Mvc" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WCP.Mvc" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="WCP.Mvc" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WCP.Mvc --version 8.0.0
                    
#r "nuget: WCP.Mvc, 8.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WCP.Mvc@8.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WCP.Mvc&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=WCP.Mvc&version=8.0.0
                    
Install as a Cake Tool

WCP.Mvc

WCP.Mvc 是一组面向 ASP.NET Core MVC 的辅助组件,主要包含:

  • 基于 TagHelper 的分页组件(Bootstrap 风格),通过 <pager> 标签轻松输出分页导航;

  • 针对百度 UEditor 的集成扩展,提供 AddUEditorService 注入与服务封装;

  • 一套简单的分页模型接口 IPagedList 及其实现,方便在 MVC 中统一分页结果结构。

  • Target Framework: net8.0

  • License: 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 / PagedListMetaData
  • PagedListRenderOptions:分页渲染配置
  • 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.0.0 208 11/28/2025
1.0.1 627 7/26/2021
1.0.0 585 7/22/2021