Asp.Net Core 视图整理(一)

一、部分视图的使用

注:1.目前在Asp.Net Core2.0中对于部分视图的支持主要使用

Html.Partial()/Html.PartialAsync();

Html.RenderPartial()/Html.RenderPartialAsync();

2.目前还不支持Html.Action() 方式

3.关于Html.Partial()的使用方式跟Asp.Net Mvc中相同。

二、Html.Partial()使用示例:

1.

@Html.Partial("AuthorPartial")
@{
    Html.RenderPartial("AuthorPartial");
}

2.

// Uses a view in current folder with this name
// If none is found, searches the Shared folder
@Html.Partial("ViewName")

// A view with this name must be in the same folder
@Html.Partial("ViewName.cshtml")

// Locate the view based on the application root
// Paths that start with "/" or "~/" refer to the application root
@Html.Partial("~/Views/Folder/ViewName.cshtml")
@Html.Partial("/Views/Folder/ViewName.cshtml")

// Locate the view using relative paths
@Html.Partial("../Account/LoginPartial.cshtml")

3.部分视图,指定参数调用

@Html.Partial("PartialName", customViewData)

三、视图Razor语法不同

1.@functions,在视图中定义函数

@functions {
    public string GetHello()
    {
        return "Hello";
    }
}

<div>From method: @GetHello()</div> 

更多Razor语法参考:https://docs.microsoft.com/en-us/aspnet/core/mvc/views/razor

更多:

Asp.Net Core MVC控制器和视图之间传值

.NetCore中EFCore的使用整理

VS Code搭建.NetCore开发环境(二)

原文地址:https://www.cnblogs.com/tianma3798/p/7388118.html