mercredi 26 août 2015

'IEnumerable<>' does not contain a definition for '' and no extension method '' accepting a first argument of type 'IEnumerable<>' could be found

I want to create online forum like below image

enter image description here

this is my Controller method

public ActionResult Discussion_Preview()

    int Discussion_ID = 1;

   var discussion_preview = (from d in db.AB_Discussion
                              where d.Discussion_ID == Discussion_ID
                              join dc in db.AB_DiscussionComments on d.Discussion_ID equals dc.Discussion_ID
                              join user_discussion in db.AspNetUsers on d.CreatedBy equals user_discussion.Id
                              join user_comments in db.AspNetUsers on dc.CreatedBy equals user_comments.Id
                              select new DiscussionPreview_Model
                                Disussion_ID = d.Discussion_ID,
                                Discussion_CreateDate = d.CreatedDate,
                                Discussion_CreateBy = user_discussion.UserName,
                                Discussion_Title = d.Discussion_Name,
                                Discussion_Description = d.Discription,
                                Comment_ID = dc.Comment_ID,
                                Comment_Description = dc.Comment_Discription,
                                Comment_CreateDate = dc.CreatedDate,
                                Comment_CreateBy = user_comments.UserName


    return View(discussion_preview);

Model Class

public class DiscussionPreview_Model
    public int Disussion_ID { get; set; }
    public Nullable<System.DateTime> Discussion_CreateDate { get; set; }
    public string Discussion_CreateBy { get; set; }
    public string Discussion_Title { get; set; }
    public string Discussion_Description { get; set; }

    public int Comment_ID { get; set; }
    public Nullable<System.DateTime> Comment_CreateDate { get; set; }
    public string Comment_CreateBy { get; set; }
    public string Comment_Description { get; set; }


View Page

@model IEnumerable<prjct.Models.DiscussionPreview_Model>

    ViewBag.Title = "Discussion_Preview";
    Layout = "~/Views/Shared/_Layout.cshtml";

 <h3>@Html.DisplayFor(model => model.Discussion_Title)</h3>

<div>@Html.DisplayFor(model => model.Discussion_Description)</div>
<div>@Html.DisplayFor(model => model.Discussion_CreateDate)  @Html.DisplayFor(model => model.Discussion_CreateDate)</div>

@foreach (var item in Model)


        <div class="display-field">@item.Comment_Description</div>
        <div class="display-field">@item.Comment_CreateBy : @item.Comment_CreateDate </div>


When debug above application I'm getting below error message

'IEnumerable' does not contain a definition for 'Discussion_Title' and no extension method 'Discussion_Title' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?)

Aucun commentaire:

Enregistrer un commentaire