Asp.Net Core 视图整理(一)

本文详细介绍了ASP.NET Core 2.0中部分视图的使用方法,包括Html.Partial()的不同调用方式及参数传递,并对比了Razor语法的特点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、部分视图的使用

注: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开发环境(二)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值