我正在尝试遵循有关 Razor 入门的 Microsoft 文档 https://learn.microsoft.com/en-us/aspnet/web-pages/overview/getting-started/introducing-razor-syntax-c#a-simple-code-example。当我尝试实现以下代码时,我收到注释中详细说明的错误:
Solution/Project/Pages/AddNumbers.cshtml
:
@{
var total = 0;
var totalMessage = "";
if(IsPost) { // The name 'isPost' does not exist in the current context
// Retrieve the numbers that the user entered.
var num1 = Request["text1"]; // CS0103 The name 'Request' does not exist in the current context
var num2 = Request["text2"]; // CS0103 The name 'Request' does not exist in the current context
// Convert the entered strings into integers numbers and add.
total = num1.AsInt() + num2.AsInt();
totalMessage = "Total = " + total;
}
}
我认为我已经忠实地遵循了指示,但想不出我在哪里犯了错误。解决办法是什么?
IsPost
如果您不创建它,则它不存在。您可以创建这样的属性,默认为false
并将其设置为 true 在你的OnPost
处理程序。
同样,您也不能参考Request
就像您在代码中尝试的那样,您也需要一个属性。
Since num1
and num2
未成功初始化,无法成功转换为int
either.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)