0

我正在尝试创建一个简单的联系表格。这是我的模型:

Imports System.Data.Entity
Imports System.ComponentModel.DataAnnotations

Public Class Contact

    Public Property Name() As String
    Public Property Title() As String
    Public Property Company() As String
    Public Property CompanyAddress() As String
    Public Property PhoneNumber() As String
    Public Property NumberOfEmployees() As String
    Public Property EmailAddress() As String
    Public Property Subject() As String
    Public Property Message() As String

End Class

这是我的观点:

@ModelType MyBlog.Contact
@Code
    ViewData("Title") = ViewBag.Title
End Code
@Using Html.BeginForm()

    @Html.LabelFor(Function(model) model.EmailAddress)
    @Html.EditorFor(Function(model) model.EmailAddress)
    @Html.ValidationMessageFor(Function(model) model.EmailAddress)

    @<input type="submit" value="Send" />

End Using

而且,这是我的控制器:

Function Contact() As ActionResult

    Return View("", "_FinalSubPageLayout", "")

End Function

我得到的错误是:

传入字典的模型项是“System.String”类型的,但该字典需要一个“MyBlog.Contact”类型的模型项。

我能做些什么来解决这个错误?谢谢你。

4

2 回答 2

1
 'Return View("", "_FinalSubPageLayout", "")

  Dim myModel as New Blog.Contact
  'fill myModel

  Return View("", "_FinalSubPageLayout", myModel)

我不确定首先"",您可能需要指定实际名称或传递 Nothing 或其他内容。

于 2012-10-02T14:10:26.283 回答
1

您正在将""模型作为模型传递给需要类型模型的视图MyBlog.Contact。我不确定这两个""参数中的哪一个应该是模型,但是您需要将其作为一个实例MyBlog.Contact或使用不需要模型的重载。

于 2012-10-02T14:18:22.720 回答