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

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(); 
} 
主站蜘蛛池模板: 琼结县| 印江| 招远市| 鄂伦春自治旗| 平塘县| 湛江市| 泌阳县| 义乌市| 黔南| 赤壁市| 砚山县| 贵德县| 肇东市| 南木林县| 徐州市| 石嘴山市| 中方县| 盐池县| 宣武区| 辉南县| 枝江市| 元谋县| 章丘市| 冷水江市| 彭阳县| 承德市| 六盘水市| 涟源市| 安康市| 平定县| 涞水县| 肇源县| 汝州市| 泾源县| 阿荣旗| 清苑县| 绥宁县| 鹤岗市| 黑水县| 长沙市| 公安县|