-2

I have a view in cshtml and some model to view values in a columns. In a columns Name4 and Name5 I want to show values from second model and I don't know how to do it. For example now I showing values from model Project.Models.Names but in a column Name4 and Name5 I want to show values from model Project.Models.Surnames for example.

@model IEnumerable<Project.Models.Names>



@{
ViewBag.Title = "Smt";

}

<h2>Smt</h2>


<table class="table">
<tr>
    <th>
        Name
    </th>
    <th>
        Name1
    </th>
    <th>
        Name2
    </th>
    <th>
        Name3
    </th>
    <th>
        Name4
    </th>
    <th>
        Name5
    </th>
    <th>

    </th>
</tr>

@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Name)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Name1)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Name2)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Name3)
    </td>
    <td>
        ...value from second model
    </td>
    <td>
        ...value from second model
    </td>
Rand Random
  • 7,300
  • 10
  • 40
  • 88
manhart
  • 19
  • 5

1 Answers1

0

Create a Viewmodel class that has properties of Name and Surname. Then bind to that.

Rich Bryant
  • 865
  • 10
  • 27