Asp.net mvc ASP.NET MVC:强类型视图中的模型未填充

Asp.net mvc ASP.NET MVC:强类型视图中的模型未填充,asp.net-mvc,vb.net,Asp.net Mvc,Vb.net,我是ASP.NET MVC的新手,我正在通过一个教程学习基本知识。本教程是用C#编写的,我正在将其转换为VB,以便与一些相关项目保持一致。我必须假设我在转换过程中遗漏了一些东西,但我无法理解它可能是什么 我有以下课程: Public Class GuestResponse Public Name As String Public Email As String Public Phone As String Public WillAttend As Boolean?

我是ASP.NET MVC的新手,我正在通过一个教程学习基本知识。本教程是用C#编写的,我正在将其转换为VB,以便与一些相关项目保持一致。我必须假设我在转换过程中遗漏了一些东西,但我无法理解它可能是什么

我有以下课程:

Public Class GuestResponse
    Public Name As String
    Public Email As String
    Public Phone As String
    Public WillAttend As Boolean?
End Class
以及与该类相关的强类型视图:

@ModelType PartyInvites.GuestResponse

@Code
    Layout = Nothing
End Code

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>RsvpForm</title>
</head>
<body>
    @Using Html.BeginForm
        @<p>Your name: @Html.TextBoxFor(Of String)(Function(x) x.Name)</p>
        @<p>Your email: @Html.TextBoxFor(Of String)(Function(x) x.Email)</p>
        @<p>Your phone: @Html.TextBoxFor(Of String)(Function(x) x.Phone)</p>
        @<p>
            Will you attend?
            @Html.DropDownListFor(Of Boolean?)(Function(x) x.WillAttend,
                                                        New SelectListItem() {New SelectListItem With {.Text = "Yes, I'll be there", .Value = Boolean.TrueString},
                                                        New SelectListItem With {.Text = "No, I can't come", .Value = Boolean.FalseString}}, "Choose an option")
        </p>
        @<input type="submit" value="Submit RSVP" />
    End Using
</body>
</html>
@ModelType PartyInvites.GuestResponse
@代码
布局=无
结束代码
RsvpForm
@使用Html.begin
@ 您的姓名:@Html.TextBoxFor(共字符串)(函数(x)x.name)

@ 您的电子邮件:@Html.TextBoxFor(共字符串)(函数(x)x.email)

@ 您的手机:@Html.TextBoxFor(共串)(函数(x)x.phone)

@ 你会参加吗? @函数(x)x.willAttention, New SelectListItem(){New SelectListItem With{.Text=“是的,我会在那里,.Value=Boolean.TrueString}, 带有{.Text=“否,我不能来”,.Value=Boolean.false字符串}}的新SelectListItem,“选择一个选项”)

@ 终端使用
我的控制器有一个简单的操作方法,它接受该类并用另一个视图响应:

<HttpPost>
Function RsvpForm(g As GuestResponse) As ViewResult
    'TODO: Email response to the party organizer
    Return View("Thanks", g)
End Function

函数RsvpForm(g作为GuestResponse)作为ViewResult
'待办事项:给聚会组织者的电子邮件响应
返回视图(“谢谢”,g)
端函数
不幸的是,post请求中的表单数据没有填充到我的GuestResponse类中。如果在该操作方法中插入断点,则所有GuestResponse属性都为空。同时,Request.Form值看起来和预期的一样——它们只是没有填充GuestResponse对象


我肯定我少了一些小东西。非常感谢您的帮助。

尝试将
属性添加到
g
参数

我已经弄明白了。显然,ASP.NET只会填充对象的属性-我的对象只有公共字段

因此:

Public Class GuestResponse
    Public Name As String
    Public Email As String
    Public Phone As String
    Public WillAttend As Boolean?
End Class
应该是:

Public Class GuestResponse
    Public Property Name As String
    Public Property Email As String
    Public Property Phone As String
    Public Property WillAttend As Boolean?
End Class

感谢大家的参与。

您的
Html.BeginForm
->
(“请求”、“控制器”,方法:=FormMethod.Post)
??@RyanWilson本教程没有指出任何参数。我尝试显式添加它们并得到相同的结果-对象属性仍然为空。我相信该属性是特定于ASP.NET核心的。Intellisense无法识别它,我无法编译。是的,我以为你在使用ASP.NET核心。