.net core 使用ViewComponent
.net core 中的局部视图组件是ViewComponent,可以用于建制重复使用公共功能组件
一、新建一个类DemoViewComponent(必须以ViewComponent结尾)且继承ViewComponent
using Microsoft.AspNetCore.Mvc;
using NetCoreApiDemo.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks; namespace NetCorePortal.Components
{
public class DemoViewComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync()
{
List<tbl_page> pageList = new List<tbl_page>();
for (int i = ; i < ; i++)
{
pageList.Add(new tbl_page()
{
page_no = i.ToString(),
page_name = i.ToString()
});
}
return View(pageList);//此处没有返回ViewName 对应的视图文件是Default.cshtml
//return View("D", pageList);//此处返回的ViewName 是“D” 对应的视图文件是D.cshtml
}
}
}
二、在View/Share目录下建立Components目录,并在此目录下建立Demo目录及对应Default.cshtml文件
@model IEnumerable<NetCoreApiDemo.Model.tbl_page>
<h1>Demo IViewComponentResult</h1>
<table>
<tr>
<th>page_no</th>
<th>page_name</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.page_no</td>
<td>@item.page_name</td>
</tr>
}
</table>
三、调用上面建立的 DemoViewComponent
@{
ViewData["Title"] = "Home Page";
}
@await Component.InvokeAsync("Demo")
.net core 使用ViewComponent的更多相关文章
- 9.2.4 .net core 通过ViewComponent封装控件
我们在.net core中还使用了ViewComponent方式生成控件.ViewComponent也是asp.net core的新特性,是对页面部分的渲染,以前PartialView的功能,可以使用 ...
- [转].net core 通过ViewComponent封装控件 左侧菜单
本文转自:http://www.cnblogs.com/BenDan2002/p/6224816.html 我们在.net core中还使用了ViewComponent方式生成控件.ViewCompo ...
- ASP.NET MVC Core的ViewComponent
MVC Core新增了ViewComponent的概念,直接强行理解为视图组件,用于在页面上显示可重用的内容,这部分内容包括逻辑和展示内容,而且定义为组件那么其必定是可以独立存在并且是高度可重用的. ...
- .net core使用ViewComponent将页面图片转码成base64
using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; usi ...
- 面向云的.net core开发框架
目录结构 1 为什么搭建面向云的.Net core云开发框架 2 主要设计思路 3 项目解决方案 4 基础设施层 4.1反射工具 4.2多级可换源的配置(上) 42多级可换源的配置(下) 4.3可配置 ...
- .net core 学习笔记(4)-ViewComponent
动态菜单,以前用的是Html.Action(url)来获取的,到了 .net core 中忽然发现没有了这个方法,原来在 .net core 中是提供了个 ViewComponent,有点类似以前的用 ...
- ASP.NET CORE 自定义视图组件(ViewComponent)注意事项
*红色字体为固定命名,蓝色为一般命名规则,黄色为ASP.NET CORE 默认查找文件名 概要:1.简单ViewComponent的用法 2.ViewComponent控制器返回值 3.注意事项 1 ...
- .Net Core使用视图组件(ViewComponent)封装表单文本框控件
实例程序的界面效果如下图所示: 在表单中的搜索条件有姓名,学号,成绩.他们在一行中按照水平三等分排列. 在cshtml中用html实现上述表单效果的的代码如下: <form class=&quo ...
- Asp.net core 学习笔记 ( ViewComponent 组件 )
refer : https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-components core 和 Angular 的 comp ...
随机推荐
- python爬虫网页解析之lxml模块
08.06自我总结 python爬虫网页解析之lxml模块 一.模块的安装 windows系统下的安装: 方法一:pip3 install lxml 方法二:下载对应系统版本的wheel文件:http ...
- Spring Boot 2.2.2.RELEASE 版本中文参考文档【3.2 - 3.10】
Spring Boot 2.2.2.RELEASE版本中文文档持续更新中~如有需要获取参考文档文件,关注公众号JavaSo,回复“参考文档”即可. 3.2 结构化代码 Spring Boot不需要任何 ...
- for循环使用element的折叠面板遇到的问题-1
首先,效果是点击添加折叠面板,折叠面板的title右侧是关闭的小按钮,每次添加的面板都自动展开,其他的面板自动关闭,但其中发现一个问题是,每次点击关闭的时候,虽然上一个面板被关闭了,但他的下一个会自动 ...
- 如何获取input,file里的文件,实现预览效果,并传给后端?
单纯的事件与获取 <input type="file" name="file" id="fileUpload"> <img ...
- RMAN 'Duplicate From Active Database' Feature in Oracle11g (Doc ID 452868.1)
RMAN 'Duplicate From Active Database' Feature in Oracle11g (Doc ID 452868.1) APPLIES TO: Oracle Data ...
- Docker 镜像介绍和命令
目录 是什么 UnionFS(联合文件系统) Docker镜像加载原理 分层的镜像 为什么 Docker 镜像要采用这种分层结构呢 特点 Docker镜像commit操作补充 案例演示 1.从Hub上 ...
- 002 C/C++ 数组的传递
传递一个数组给一个函数的正确做法: 1.传递数组的内存首地址. 2.传递数组的有效长度.指数组的元素数量. 编译器总是将数组类型的变量作为指针传递. 计算数组的长度: int length = siz ...
- C# 常用排序算法
文章引用地址:https://www.cnblogs.com/fengyeqingxiang/archive/2019/06/14/11021852.html C#所有经典排序算法汇总 1 2 3 ...
- 浅谈python之利用pandas和openpyxl读取excel数据
在自学到接口自动化测试时, 发现要从excel中读取测试用例的数据, 假如我的数据是这样的: 最好是每行数据对应着一条测试用例, 为方便取值, 我选择使用pandas库, 先安装 pip instal ...
- linux 安装程序的方式
linux 安装程序的方式 通用二进制格式(绿色软件,打开即用) 软件包管理器(rpm) 软件包管理器的前端工具(yum) 源代码编译