当我在Visual Studio 2017中创建一个新的Razor页面时,分离的代码后置文件没有被创建。
这是突出显示此问题的屏幕截图。
我们可以看到名为List.cshtml的Razor页面没有包含代码后置文件。与默认页面about.cshtml相比较。
这是突出显示此问题的屏幕截图。
我们可以看到名为List.cshtml的Razor页面没有包含代码后置文件。与默认页面about.cshtml相比较。
1 - 在"餐厅"上右键单击,添加类:
2 - 在您的情况下,将其命名为List.cshtml.cs。这将创建代码后台。现在它需要进行连接。打开已创建的类。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
//Add the MVC usings
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
//TODO The namespace will be correct in your code
namespace app_name.Pages.resturants
{
//public class List
//TODO correct the model name and inherit PageModel
public List1Model : PageModel
{
public void OnGet()
{
}
}
}
3 - 在 List.cshtml 中:
@page
@model app_name.Pages.resturants.List1Model
@{
}
有关修改https://learn.microsoft.com/en-gb/aspnet/core/data/ef-rp/sort-filter-page?view=aspnetcore-5.0背后的代码的更多信息,请参见此处。
Page1.razor
时,您可以添加CSS、CS和JS分组文件,当您将它们命名为Page1.razor.css
、Page1.razor.ss
或Page1.razor.js
时。 - KargWare