Hello friend I have a problem in mvc 4 to send a dynamic model in View suggest me how to bind dynamic model with the view
Here is my Action
[ChildActionOnly]
public ActionResult TopArticles()
{
var model = from a in db.Articles.Take(3).OrderBy(m=>m.TotalViews)
join u in db.UserProfiles
on a.CreatedBy equals u.ID
join t in db.Tags
on a.TagID equals t.ID
select new
{
Title = a.Title,
ArticleID = a.ArticleID,
FirstName = u.FirstName,
CreatedBy = a.CreatedBy,
TagID = a.TagID,
TagName = t.Name,
CreationDate = a.CreationDate,
TotalViews = a.TotalViews
}; // get Top 3 Articles from Articles
return PartialView(model);
}
And Here is my View
@model IEnumerable<dynamic>
@{
ViewBag.Title = "TopArticles";
}
@foreach(dynamic item in Model)
{
<div class="row about_topviewedarticle1">
<div class="row">
<div class="columns twenty">
<a href="#" class="title">@item.Title</a>
by <a href="#"class="profilefont_eleven">@item.FirstName</a>
</div>
</div>
<div class="row">
<div class="columns twenty">
<label class="font_ten">views: @item.TotalViews posted on : @item.CreationDate</label>
</div>
</div>
</div>
}
When I run this code following error is showing
'object' does not contain a definition for 'Title'