【发布时间】:2018-04-01 23:09:54
【问题描述】:
当使用带有连字符的文件名的 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(没有连字符)会很好。
有谁知道如何解决这个问题?
【问题讨论】:
-
我不知道这是一个错误还是设计强加的约束。每个 razor 页面都可以有一个名为
Contact-Us.cshtml.cs的代码隐藏文件,类为Contact-Us。这似乎不是一个有效的类名。也许错误消息可以改进,但这听起来像是设计不允许的。
标签: c# razor asp.net-core .net-core razor-pages