2015-12-04 3 views
0

Я постоянно получаю свою ошибку:(VB.NET MVC) Модель элемент передается в словарь типа «System.Data.Entity.DynamicProxies

The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Project_AEA0128FB0789822CECB09AA20866E2B89F29798BE9DFF48A921561C8509DA33', but this dictionary requires a model item of type 'webapp.ProjectModel'.

Это мой прибудет Просмотр код:

' GET: Projects/Edit/5 
Function Edit(ByVal id As Integer?) As ActionResult 
    If IsNothing(id) Then 
     Return New HttpStatusCodeResult(HttpStatusCode.BadRequest) 
    End If 
    Dim project As Project = db.Projects.Include(Function(i) i.Info).Include(Function(p) p.Files).Where(Function(w) w.Id = id).First() 
    If IsNothing(project) Then 
     Return HttpNotFound() 
    End If 
    Return View(project) 
End Function 

И это мой взгляд модель:

Public Class ProjectModel 
    Public Property Id As Integer 

    <Required> 
    <Display(Name:="Project Naam")> 
    <MaxLength(250)> 
    Public Property Naam As String 

    <Required> 
    <DisplayFormat(NullDisplayText:="NotSpecified", DataFormatString:="{0:dd-MM-yyyy}")> 
    <Display(Name:="Begin Datum")> 
    Public Property BeginDate As Date 

    <Display(Name:="Eind Datum")> 
    Public Property EndDate As Date? 

    <Required()> 
    <Display(Name:="Project Manager")> 
    Public Property ProjectManagerId As String 

    <Required()> 
    <Display(Name:="Google Map Link")> 
    Public Property GoogleMapLink As String 

    <Required> 
    <Display(Name:="Address")> 
    <MaxLength(250)> 
    Public Property Address As String 

    <Required> 
    <Display(Name:="Description")> 
    <MaxLength(250)> 
    Public Property Description As String   
End Class 

И это само по себе вид:

@ModelType Webapp.ProjectModel 
@Code 
    ViewData("Title") = "Edit2" 
End Code 

<h2>Edit2</h2> 

@Using (Html.BeginForm()) 
    @Html.AntiForgeryToken() 

    @<div class="form-horizontal"> 
     <h4>ProjectModel</h4> 
     <hr /> 
     @Html.ValidationSummary(True, "", New With { .class = "text-danger" }) 
     @Html.HiddenFor(Function(model) model.Id) 

     <div class="form-group"> 
      @Html.LabelFor(Function(model) model.Naam, htmlAttributes:= New With { .class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(Function(model) model.Naam, New With { .htmlAttributes = New With { .class = "form-control" } }) 
       @Html.ValidationMessageFor(Function(model) model.Naam, "", New With { .class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      @Html.LabelFor(Function(model) model.BeginDate, htmlAttributes:= New With { .class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(Function(model) model.BeginDate, New With { .htmlAttributes = New With { .class = "form-control" } }) 
       @Html.ValidationMessageFor(Function(model) model.BeginDate, "", New With { .class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      @Html.LabelFor(Function(model) model.EndDate, htmlAttributes:= New With { .class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(Function(model) model.EndDate, New With { .htmlAttributes = New With { .class = "form-control" } }) 
       @Html.ValidationMessageFor(Function(model) model.EndDate, "", New With { .class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      @Html.LabelFor(Function(model) model.ProjectManagerId, "ProjectManagerId", htmlAttributes:= New With { .class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.DropDownList("ProjectManagerId", Nothing, htmlAttributes:= New With { .class = "form-control" }) 
       @Html.ValidationMessageFor(Function(model) model.ProjectManagerId, "", New With { .class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      @Html.LabelFor(Function(model) model.GoogleMapLink, htmlAttributes:= New With { .class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(Function(model) model.GoogleMapLink, New With { .htmlAttributes = New With { .class = "form-control" } }) 
       @Html.ValidationMessageFor(Function(model) model.GoogleMapLink, "", New With { .class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      @Html.LabelFor(Function(model) model.Address, htmlAttributes:= New With { .class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(Function(model) model.Address, New With { .htmlAttributes = New With { .class = "form-control" } }) 
       @Html.ValidationMessageFor(Function(model) model.Address, "", New With { .class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      @Html.LabelFor(Function(model) model.Description, htmlAttributes:= New With { .class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(Function(model) model.Description, New With { .htmlAttributes = New With { .class = "form-control" } }) 
       @Html.ValidationMessageFor(Function(model) model.Description, "", New With { .class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      <div class="col-md-offset-2 col-md-10"> 
       <input type="submit" value="Save" class="btn btn-default" /> 
      </div> 
     </div> 
    </div> 
End Using 

<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 

Я не знаю, откуда эта ошибка или как ее исправить.

Любые идеи или исправления будут оценены.

Привет

Гленн

ответ

1

Ваш взгляд ожидает модель типа Webapp.ProjectModel, но вы передаете свой Project модель непосредственно вместо этого. Вам необходимо преобразовать Project в ProjectModel в действие «Изменить», прежде чем отправлять его в свой вид.

Смежные вопросы

 Смежные вопросы