我收到以下錯誤:MVC 3傳遞到字典的模型項目是A型,但本字典,需要B型的模型項目
The model item passed into the dictionary is of type '...Models.VideoPostingModel', but this dictionary requires a model item of type '...Models.RegisterModel'.
我不知道是什麼問題,因爲型號匹配...
控制器:
使用系統; using System.Collections.Generic;使用System.Linq的 ; using System.Web; using System.Web.Mvc; 使用stayyolo.Models; using System.Web.Security; using System.Data;
...Controllers
{
public class VidsPostingController : Controller
{
private dbEntities db = new dbEntities();
//
// GET: /VidsPosting/
public ActionResult Details(Guid id)
{
Posting posting = db.Postings.Find(id);
if (posting.Image == null)
{
posting.Image = new byte[0];
db.Entry(posting).State = EntityState.Modified;
db.SaveChanges();
}
//convert ENTITY MODEL CLASS TO Model
VideoPostingModel toRet = new VideoPostingModel();
toRet.linkIfVideo = posting.LinkIfVideo;
toRet.PostDate = posting.PostDate;
toRet.Titile = posting.Titile;
toRet.TypeOfPosting = posting.TypeOfPosting;
return View(toRet);
}
}
型號:
public class VideoPostingModel
{
..Variables
public VideoPostingModel()
{
...
}
}
View:
@model ...Models.VideoPostingModel
@{
ViewBag.Title = "Details";
}
<fieldset>
<legend>Posting</legend>
<div class="display-label">
Description</div>
<div class="display-field">
@Html.DisplayFor(model => model.Description)
</div>
<div class="display-label">
Title</div>
<div class="display-field">
@Html.DisplayFor(model => model.Titile)
</div>
<div class="display-label">
Post Date</div>
<div class="display-field">
@Html.DisplayFor(model => model.PostDate)
</div>
<div class="display-label">
Type Of Posting</div>
<div class="display-field">
@Html.DisplayFor(model => model.TypeOfPosting)
</div>
</fieldset>
<div id="youtubePlayerdiv"">
<p style="text-align: justify">
Video!</p>
<iframe id="youtubePlayer" class="youtube-player" type="text/html"
width="640" height="385" src="http://www.youtube.com/embed/<%=Model.LinkIfVideo%>" frameborder="0">
</iframe>
</div>
<!-- end youtubeplayerDiv div -->
我非常感謝提前的幫助下,當網站的點擊控制器的詳細方法出現正確的問題。
是否全部代碼?你能顯示RegisterModel嗎? – 2012-03-15 06:20:12
ResgisterModel只是創建該項目時獲得的基本MVC標準模型。 – Aziz 2012-03-15 14:54:34
什麼? @Sasha – Aziz 2012-03-16 05:18:21