.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 ...
随机推荐
- C#构造函数、属性的应用
using System; using System.Collections.Generic; using System.Text; namespace test { class Program { ...
- PlayJava Day015
今日所学: /* 2019.08.19开始学习,此为补档. */ StringBuffer 定义: 可变字符序列 - 线程安全的 作用:基本与String相同,也是用于描述字符串 与String的区别 ...
- Vue.js2.0快速入门笔记
vue.js 解耦视图与数据,可复用的组件,前端路由,状态管理,虚拟DOM. MVVM模式:当View(视图层)变化时,会自动更新ViewModel(视图模型),View与ViewModel之间双向绑 ...
- OpenCV:图像的合并和切分
导包: import numpy as np import cv2 import matplotlib.pyplot as plt def show(image): plt.imshow(image) ...
- 部署web01,web02,nfs,db01,backup,搭建wordpress,WeCenter,实现共享,热备,实时备份
小结 部署web01,web02,nfs,db01,backup,搭建wordpress,WeCenter,实现共享,热备,实时备份 1)在web01和web02上安装nginx和php 2)创建ww ...
- CodeForces 862B(思维+二分图染色)
题意 https://vjudge.net/problem/CodeForces-862B 给出n个点,n-1条边,求再最多再添加多少边使得二分图的性质成立 思路 因为题目是求的最多添加多少边,所以可 ...
- UML工具-1-StarUML下载及破解
UML工具-StarUML 下载地址 http://staruml.io/
- go语言设计模式之template
template.go package template import ( "strings" ) type MessageRetriever interface { Messag ...
- ACWING 95 费解的开关 解题记录
你玩过“拉灯”游戏吗?25盏灯排成一个5x5的方形.每一个灯都有一个开关,游戏者可以改变它的状态.每一步,游戏者可以改变某一个灯的状态.游戏者改变一个灯的状态会产生连锁反应:和这个灯上下左右相邻的灯也 ...
- Apriori关联分析详解
------------恢复内容开始------------ 一. Apriori关联分析概述 选择物品之间的关联规则也就是要找出物品之间的关系,要找到这种关系有两步 找出频繁一起出现的物品集的集合, ...