وقتی میخوام در کنترلر یک کوئری از دیتابیسو به مدل پاس بدم این خطارو میزنه
The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Tbl_Categorys_26FAF8D301E15B0158E967BAE1EAE74FFE13A2BB70503E270542F343CFB2ADAB', but this dictionary requires a model item of type 'RanaShop.Models.Domain.Tbl_User
کنترلر
public ActionResult Product(int id)
{
var q = (from a in db.Tbl_Categorys
where a.ID.Equals(id) && (a.ExitCount > 0)
select a).SingleOrDefault();
if (q == null)
{
ViewBag.Message = "محصولی برای نمایش وجود ندارد";
ViewBag.Class = "alert alert-danger";
ViewBag.Style = "width: 40%;padding:15px;background-color:rgb(248,215,218);border
radius:5px;text-align:right;top:20px;margin:0 auto";
return View();
}
return View(q);
}
ویو
@model Shop.Models.Domain.Tbl_Categorys
@{
ViewBag.Title = @Model.Title;
Layout = "~/Views/Shared/_Layout.cshtml";
Shop.Models.Domain.DBEntities db = new Shop.Models.Domain.DBEntities();
}
<div style="@ViewBag.Style" class="@ViewBag.Class">
@if (ViewBag.Style != null)
{
<button type="button" class="close" data-dismiss="alert" style="float:left">×</button>
}
@Html.Raw(ViewBag.Message)
</div>
@{
if (Model != null)
{
<div class="container padding-top-10 ">
<div class="col-md-7 col-sm-7 col-xs-12">
<div class="well">
<strong>
@Model.Title
</strong>
<p class="help-block ">
@Model.City
</p>
</div>
<span class="line-height-30 " style="font-family:'B Titr'">
@Html.Raw(Model.Text)
</span>
<hr />
<div class="shop-item-price padding-bottom-10 ">
<span>
<strong>
Price : @Model.Price Dollor
</strong>
</span>
</div>
</div>
</div>
}
else
{
<p>
محصولی برای نمایش وجود ندارد
</p>
}
}
}
سلام دوستان . من خودم تونستم مشکلو برطرف کنم 😄
ممنون از کمکتون😂
مشکلم از layout بود که صفحه محصولات بهش وصل بود و اونجا من model شو به جدول کاربر وصل کرده بودم بعد تو صفحه محصولات که کد ها در وسط layout قرار میگیره اومده بودم model داده بودم و ی کار مسخره بود . الان درست شد .
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)