官术网_书友最值得收藏!

ASP.NET Core Razor Pages

Razor syntax-based pages have been introduced in ASP.NET Core. Now, developers can develop applications and write syntax on the HTML with no controller in place. Instead, there is a code behind file where other events and logic can be handled. The backend page class is inherited from the PageModel class and its member variables and methods can be accessed using the Model object in Razor syntax. The following is a simple example that contains the GetTitle method defined in the code-behind class and used in the view page:

public class IndexModel : PageModel 
{ 
  public string GetTitle() => "Home Page"; 
}

Here is the Index.cshtml file that displays the date by calling the GetCurrentDate method:

@page 
@model IndexModel 
@{ 
  ViewData["Title"] = Model.GetTitle(); 
} 
主站蜘蛛池模板: 宣汉县| 左云县| 察雅县| 桐乡市| 镇赉县| 车险| 凤翔县| 罗山县| 铁岭市| 太白县| 青冈县| 叶城县| 茶陵县| 叶城县| 萝北县| 涞水县| 汝城县| 伊宁市| 甘南县| 蕉岭县| 顺义区| 汾西县| 沙河市| 诏安县| 雅江县| 体育| 廊坊市| 临安市| 普宁市| 大邑县| 六盘水市| 汾西县| 房山区| 霍城县| 普定县| 贺州市| 盐津县| 兴城市| 景宁| 台东市| 甘泉县|