问题标签 [razor-pages]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 在另一个程序集中找到 Razor Pages
我想在另一个程序集中找到 My Project Razor Pages。为此,我编写了以下代码:
我的解决方案:
运行localhost:5000/SameTodo
获取以下错误时:
缺少一个或多个编译参考。确保您的项目正在引用“Microsoft.NET.Sdk.Web”并且“PreserveCompilationContext”属性未设置为 false。
堆:
找不到类型或命名空间名称“SameTodoModel”(您是否缺少 using 指令或程序集引用?) + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; 私人套装;找不到类型或命名空间名称“SameTodoModel”(您是否缺少 using 指令或程序集引用?) + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore .Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; 找不到类型或命名空间名称“SameTodoModel”(您是否缺少 using 指令或程序集引用?) + public SameTodoModel Model => ViewData.Model; 类型或命名空间名称“SameTodoModel”
并设置PreserveCompilationContext
为false,但现在工作了我该如何解决这个问题?
asp.net-core - 如何在没有数据上下文的情况下搭建 Razor 页面?
当我执行以下行来搭建剃须刀页面时:
dotnet aspnet-codegenerator razorpage -m EncryptTextModel -udl -outDir Pages\EncryptTextModel --referenceScriptLibraries
我得到这个输出:
Building project ...
Finding the generator 'razorpage'...
Running the generator 'razorpage'...
Please provide a valid dataContext
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:06.71
此页面不会将数据持久化到数据库,因此它不需要 dataContext - 它只是加密文本。如何让 ASP.NET 在没有数据上下文的情况下为该页面搭建基架?
我目前正在使用 Visual Studio 2017。我使用本教程作为我的指南。
asp.net - 为什么 Razor Pages 是在 Asp.net Core 中创建 Web UI 的推荐方法?
学习新事物需要时间、空间和精力的投入。我目前正在学习 Asp.Net Core MVC 2.0。此ASP.NET Core 教程概述指出:
Razor Pages 是使用 ASP.NET Core 创建 Web UI 的推荐方法
这些信息让我在决定是否必须停止学习 Asp.net Core MVC 并开始学习 Asp.net Core Razor Pages 时感到困惑。
- 为什么 Razor Pages 是在 Asp.net Core 中创建 Web UI 的推荐方法?
欢迎任何方向。
c# - Page() 在 Razor Page 中有什么作用?
我想知道为什么处理程序可以是 voidOnGet
或.IndexModel
return Page();
实际上是做什么的Page()
?
c# - 文件名包含连字符的 RazorPages 会导致 IntelliSense 中断
将 RazorPages 与包含连字符的文件名一起使用时,它会导致 Visual Studio 的工具在有效代码上显示红色波浪线。
以下是我看到的一些常见错误:
"The name ViewData does not exist in the current context"
"The name TempData does not exist in the current context"
"The name Model does not exist in the current context"
例如,我的 RazorPage 调用Contact-Us.cshtml
(带有连字符)会出错
然而,我的页面ContactUs.cshtml
(没有连字符)会很好。
有谁知道如何解决这个问题?
c# - 如何向 RazorPages 添加授权?
我查看了当前的官方 Microsoft Docs,但找不到任何正确涵盖如何处理 RazorPages 授权的内容。
我发现您可以将其添加AuthorizeAttribute
到PageModel
类似内容中:
我不想对每一页都重复这个。有没有更好的办法?
asp.net-core - Asp.net core razor pages 加载部分页面
我使用 asp.net core 2 的新功能 Razor 页面。在 _layout.cshtml 中。
_layoutHeader.cshtml 是带有代码的页面。
@RenderBody 将使用 pagemodel 加载 index.cshtml。
运行项目。抛出错误:
InvalidOperationException:传递到 ViewDataDictionary 的模型项的类型为“Yiko.Ent.WebRazorPages.Pages.Home.IndexModel”,但此 ViewDataDictionary 实例需要“Yiko.Ent.WebRazorPages.Pages._LayoutHeaderModel”类型的模型项。Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.EnsureCompatible(对象值)
c# - 将 ASP.NET Core 2 Razor Pages 默认目录名称更改为 wwwroot
ASP.NET Core 2.0 的新关键特性之一是 Razor Pages。我已经能够在默认/Pages
文件夹和任何其他自定义文件夹中使用它们,例如/RazorPages
将其放入我的startup.cs
文件中。
如本文所述:http ://www.talkingdotnet.com/change-asp-net-core-razor-pages-default-directory-name/
但是,当我尝试将默认 Razor Pages 目录设为/wwwroot
文件夹时,它会忽略我在“代码隐藏”.cs 文件中声明的任何命名空间或模型。像这样:
我猜是因为 .cs 文件无法从面向公众的/wwwroot
文件夹中访问。
有谁知道如何使 Razor Pages 成为默认目录/wwwroot
?
我认为 Razor Pages 功能在未来会被大量使用。
感谢您的帮助。
asp.net-core - razor pages 核心本地方法
可以直接从 HTML 调用剃须刀页面的 @functions{} 部分中的方法吗?这似乎工作正常,并且比调用 API 容易得多,但我想知道这是否有缺点(安全性、性能等)?
例如,在代码中...
和HTML...