gpt4 book ai didi

asp.net - Visual Basic 中的 @Html.BeginForm 语法

转载 作者:行者123 更新时间:2023-12-02 14:32:45 25 4
gpt4 key购买 nike

我正在使用 ASP.NET MVC 5 和 Visual Studio Express 2013。我在 C# 项目中有这个小表单:

<body>
@using (Html.BeginForm())
{
<p>Your name: @Html.TextBoxFor(x => x.Name) </p>
<p>Your email: @Html.TextBoxFor(x => x.Email) </p>
<p>Your phone: @Html.TextBoxFor(x => x.Phone) </p>
}
</body>

我尝试将上面的代码翻译成VB.NET,如下所示:

<body>
@Using Html.BeginForm()
<p>Your name: @Html.TextBoxFor(Function(m), m.Name)</p>
<p>Your email: @Html.TextBoxFor(Function(m), m.Email)</p>
<p>Your phone: @Html.TextBoxFor(Function(m), m.phone)</p>
End Using
</body>

每个“P”元素中的“Your”下方都有蓝线。当我将鼠标悬停在蓝线上时,提示帮助是“属性说明符不是完整的语句”。使用续行符将该属性应用于以下语句。'.

当我调试页面时,错误为“BC30201:需要表达式”。在 @Using 发生的行上。

我做错了什么?

最佳答案

正如 @rogerdeuce 猜测的那样,你不需要第二个 @符号。

@用于将上下文从 VB 代码切换到 HTML/文本。

所以正确的代码如下:

<body>
@Using Html.BeginForm()
@<p>Your name: @Html.TextBoxFor(Function(m) m.Name)</p>
@<p>Your email: @Html.TextBoxFor(Function(m) m.Email)</p>
@<p>Your phone: @Html.TextBoxFor(Function(m) m.phone)</p>
End Using
</body>

或者您可以使用 @<text>快捷方式:

<body>
@Using Html.BeginForm()
@<text>
<p>Your name: @Html.TextBoxFor(Function(m) m.Name)</p>
<p>Your email: @Html.TextBoxFor(Function(m) m.Email)</p>
<p>Your phone: @Html.TextBoxFor(Function(m) m.phone)</p>
</text>
End Using
</body>

关于asp.net - Visual Basic 中的 @Html.BeginForm 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34800689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com