HI ive got a questuin. Ive got 4 models
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;
using System.Web;
model1:
namespace TelerikMvcApp1.Models
{
public class CollectorStatus
{
[Key]
public int CollectorID { get; set; }
public DateTime LastStart { get; set; }
public DateTime LastChecked { get; set; }
public Boolean ServiceRunning { get; set; }
public int? LastBatchID { get; set; }
public Boolean BatchCompleted { get; set; }
public Byte? BatchErrorID { get; set; }
}
public class CollectorStatusContext : DbContext
{
public DbSet<CollectorStatus> Collectors { get; set; }
}
}
model2:
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace TelerikMvcApp1.Models
{
public class DataFilesStatus
{
[Key]
public int LastDataFileID { get; set; }
public string DatFileName { get; set; }
public Boolean? DataFileCompleted { get; set; }
public int? DataFileErrorID { get; set; }
public int? CollectorID { get; set; }
}
public class DataFilesStatusContext : DbContext
{
public DbSet<DataFilesStatus> DataFiles { get; set; }
}
}
model3:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace TelerikMvcApp1.Models
{
public class ProgramStatus
{
[Key]
public string ProgramName { get; set; }
public DateTime ProgramLastRun { get; set; }
}
public class ProgramStatusContext : DbContext
{
public DbSet<ProgramStatus> Stats { get; set; }
}
}
model4:
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace TelerikMvcApp1.Models
{
public class ProgramCollectorDataFilesStatus
{
public ProgramStatus ProgramStatus { get; set; }
public CollectorStatus CollectorStatus { get; set; }
public DataFilesStatus DataFilesStatus { get; set; }
}
public class ProgramCollectorDataFilesStatusContext : DbContext
{
public DbSet<ProgramCollectorDataFilesStatus> Stats { get; set; }
}
}
HTML:
@using System.Web.Mvc.Html
@using TelerikMvcApp1.Controllers
@using TelerikMvcApp1.Models
@model ProgramCollectorDataFilesStatus
@{
ViewBag.Title = "Home Page";
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<br />
<div class="container">
<div class="row">
<div class="col-md-3">
<h3>Date last run</h3>
@Html.Partial("_ProgramStatus", Model.ProgramStatus)
</div>
<div class="col-md-5">
<h3>Collector statistics</h3>
@Html.Partial("_CollectorStatus", Model.CollectorStatus)
</div>
<div class="col-md-4">
<h3>Datafiles statistics</h3>
@Html.Partial("_DataFilesStatus", Model.DataFilesStatus)
</div>
</div>
</div>
</body>
</html>
However when i run the webapp i get the following error.:
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=The model item passed into the dictionary is of type 'TelerikMvcApp1.Models.ProgramCollectorDataFilesStatus', but this dictionary requires a model item of type 'TelerikMvcApp1.Models.ProgramStatus'.
Source=System.Web.Mvc
StackTrace:
bij System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value)
bij System.Web.Mvc.ViewDataDictionary.set_Model(Object value)
bij System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary)
bij System.Web.Mvc.ViewDataDictionary`1..ctor(ViewDataDictionary viewDataDictionary)
bij System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData)
bij System.Web.Mvc.WebViewPage.set_ViewData(ViewDataDictionary value)
bij System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
bij System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
bij System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
bij System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
bij System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model)
bij ASP._Page_Views_Home_Index_cshtml.Execute() in c:\Users\cli\Desktop\test\TelerikMvcApp1\TelerikMvcApp1\Views\Home\Index.cshtml:regel 26
bij System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
bij System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
bij System.Web.WebPages.StartPage.RunPage()
bij System.Web.WebPages.StartPage.ExecutePageHierarchy()
bij System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
bij System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
bij System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
bij System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
bij System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
bij System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
bij System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
InnerException:
Does anyone how this can be fixed !!