0

I'm a newbie in MVC. Sorry all professionals for this question.

I have a model like:

public class Student
{

    public int ID { get; set; }

    public int Number{ get; set; }
    public string Name{ get; set; }
    public string Surname{ get; set; }
    public bool IsStudentNow { get; set; }

}

In my "paged" index.cshtml page, i call this model like this;

@model PagedList.IPagedList<WebProj.Models.Student>

It's ok for the paging or foreach statement but I can't access the model property in HTML helper.

For example;

I can't access this property;

@Html.DisplayNameFor(model=> model.Number)

@Html.DisplayNameFor(model=> model.Name)

But I can access this;

@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Number)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Name)
    </td>

So, I want to access model properties in HTML helper. Don't prefer to use view model.

Anonymous
  • 11,740
  • 3
  • 40
  • 50
AhuraMazda
  • 460
  • 4
  • 22
  • your model is a list of WebProj.Models.Student, so when you try to access model.Number you need to specify which item of the list, Model[0].Number – DanielVorph Jun 20 '16 at 23:46
  • I don't expect that reccomendation work, but it works. thank you. But I couldn't understand what was I do. Why Model[].Number dont get the value. I think it gets the value not the label. – AhuraMazda Jun 22 '16 at 20:41

0 Answers0