2012-10-02 55 views
0

我正在嘗試創建一個簡單的聯繫人窗體。這裏是我的模型:無法在MVC中創建聯繫人窗體3

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'類型的模型項目。

我該如何解決這個錯誤?謝謝。

回答

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

    Dim myModel as New Blog.Contact 
    'fill myModel 

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

我不知道有關第一"",您可能需要指定實際名稱或通過沒有什麼的。

+0

謝謝,但它不是一個變量。它是一個佈局名稱'_FinalSubPageLayout.vbhtml'。你可以將它替換爲View(),它將渲染具有相同錯誤的視圖(不在佈局中)。 – user1477388

+0

對,我必須查看過載情況。編輯... –

+0

真的很好趕,夥計們。我沒有意識到我必須在那裏發送模型。 – user1477388

1

您正在將""作爲模型傳遞給您的視圖,該視圖需要MyBlog.Contact類型的模型。不知道在我的頭頂,這兩個""參數中哪個參數應該是模型,但是您需要將它作爲MyBlog.Contact的一個實例,或者使用不需要模型的重載。

+0

真的很好趕,夥計們。我沒有意識到我必須在那裏發送模型。 – user1477388