jeudi 2 février 2017

Why i am not getting data from table [duplicate]

model

public class NewsList
{
    public int Id { get; set; }
    public List<ClsNews> NewsLst { get; set; }
}
public class ClsNews
{
    public int Id { get; set; }
    public string Description { get; set; }
}
public partial class News
{
    public int Id { get; set; }
    public Nullable<System.DateTime> Date { get; set; }
    public string Description { get; set; }
    public Nullable<bool> IsActive { get; set; }
}

view

<table class="table">
    @{int i = 1;}
    @for (var j = 0; j < Model.NewsLst.Count; j++)
    {
        <tr> 
            <td>
                @Html.HiddenFor(m => Model.NewsLst[j].Id)
                @Html.HiddenFor(m => Model.NewsLst[j].Description)
                @Html.DisplayFor(m => Model.NewsLst[j].Description.Substring(0,20))
                @Html.ActionLink("Read More", "NewsInnerPage", "News")
            </td>
        </tr>
        i++;
    }

controller

public ActionResult News()
{
    var res = db.News
     .Select(t => new ClsNews
     {
         Description = t.Description
     }).ToList();
    return View(res);
}

It seems to occur an error

"The model item passed into the dictionary is of type 'System.Collections.Generic.List'1[A.Models.ClsNews]' but this dictionary requires a model item of type 'A.Models.NewsList'"

I need to get the data in the description column to get to the view page. but that occurs an error. How can I resolve my problem?

Aucun commentaire:

Enregistrer un commentaire