仅在视图中显示学校及其员工的信息?

时间:2018-12-20 15:22:25

标签: c# asp.net asp.net-mvc

因此,我正在ASP.NET MVC中从事一个项目,在该项目中,我必须创建一个Web应用程序,以单个视图显示学校的信息以及有关其雇员的信息。我完成了,但是没有按我的意愿工作。 View,它向我显示了学校的信息以及员工的信息,但我像这样How it should be单独需要它。

这是此VIEW的代码:

@model IEnumerable<ProjekatFinalni.Models.Zajedno>

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
@Html.ActionLink("Create New", "Create")
</p>


<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.SkolaID)
</th>
<th>
@Html.DisplayNameFor(model => model.NazivSkole)
</th>
<th>
@Html.DisplayNameFor(model => model.AdresaRegistracije)
</th>
<th>
@Html.DisplayNameFor(model => model.Opstina)
</th>
<th>
@Html.DisplayNameFor(model => model.PostanskiBroj)
</th>
<th>
@Html.DisplayNameFor(model => model.MaticniBrojSkole)
</th>
<th>
@Html.DisplayNameFor(model => model.PIB)
</th>
<th>
@Html.DisplayNameFor(model => model.BrojRacunaSkole)
</th>
<th>
@Html.DisplayNameFor(model => model.WebStranica)
</th>
<th>
@Html.DisplayNameFor(model => model.Beleska)
</th>
<th></th>
</tr>

@foreach (var item in Model)
{ 
<tr>

<td>
@Html.DisplayFor(modelItem => item.SkolaID)
</td>

<td>
@Html.DisplayFor(modelItem => item.NazivSkole)
</td>
<td>
@Html.DisplayFor(modelItem => item.AdresaRegistracije)
</td>
<td>
@Html.DisplayFor(modelItem => item.Opstina)
</td>
<td>
@Html.DisplayFor(modelItem => item.PostanskiBroj)
</td>
<td>
@Html.DisplayFor(modelItem => item.MaticniBrojSkole)
</td>
<td>
@Html.DisplayFor(modelItem => item.PIB)
</td>
<td>
@Html.DisplayFor(modelItem => item.BrojRacunaSkole)
</td>
<td>
@Html.DisplayFor(modelItem => item.WebStranica)
</td>
<td>
@Html.DisplayFor(modelItem => item.Beleska)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { / id=item.PrimaryKey / }) |
@Html.ActionLink("Details", "Details", new { / id=item.PrimaryKey / }) |
@Html.ActionLink("Delete", "Delete", new { / id=item.PrimaryKey / })
</td>
</tr>
}

</table>

<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Ime)
</th>
<th>
@Html.DisplayNameFor(model => model.Prezime)
</th>
<th>
@Html.DisplayNameFor(model => model.RadnoMesto)
</th>
<th>
@Html.DisplayNameFor(model => model.SkolaID)
</th>
<th>
@Html.DisplayNameFor(model => model.KontaktID)
</th>
<th>
@Html.DisplayNameFor(model => model.NazivSkole)
</th>
<th>
@Html.DisplayNameFor(model => model.AdresaRegistracije)
</th>
<th>
@Html.DisplayNameFor(model => model.Opstina)
</th>
<th>
@Html.DisplayNameFor(model => model.PostanskiBroj)
</th>
<th>
@Html.DisplayNameFor(model => model.MaticniBrojSkole)
</th>
<th>
@Html.DisplayNameFor(model => model.PIB)
</th>
<th>
@Html.DisplayNameFor(model => model.BrojRacunaSkole)
</th>
<th>
@Html.DisplayNameFor(model => model.WebStranica)
</th>
<th>
@Html.DisplayNameFor(model => model.Beleska)
</th>
<th></th>
</tr>

@foreach (var item2 in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item2.Ime)
</td>
<td>
@Html.DisplayFor(modelItem => item2.Prezime)
</td>
<td>
@Html.DisplayFor(modelItem => item2.RadnoMesto)
</td>
<td>
@Html.DisplayFor(modelItem => item2.SkolaID)
</td>
<td>
@Html.DisplayFor(modelItem => item2.KontaktID)
</td>
<td>
@Html.DisplayFor(modelItem => item2.NazivSkole)
</td>
<td>
@Html.DisplayFor(modelItem => item2.AdresaRegistracije)
</td>
<td>
@Html.DisplayFor(modelItem => item2.Opstina)
</td>
<td>
@Html.DisplayFor(modelItem => item2.PostanskiBroj)
</td>
<td>
@Html.DisplayFor(modelItem => item2.MaticniBrojSkole)
</td>
<td>
@Html.DisplayFor(modelItem => item2.PIB)
</td>
<td>
@Html.DisplayFor(modelItem => item2.BrojRacunaSkole)
</td>
<td>
@Html.DisplayFor(modelItem => item2.WebStranica)
</td>
<td>
@Html.DisplayFor(modelItem => item2.Beleska)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { / id=item.PrimaryKey / }) |
@Html.ActionLink("Details", "Details", new { / id=item.PrimaryKey / }) |
@Html.ActionLink("Delete", "Delete", new { / id=item.PrimaryKey / })
</td>
</tr>
}

</table>

这是我用于VIEW的控制器的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ProjekatFinalni.Models;

namespace ProjekatFinalni.Controllers
{
public class KontaktController : Controller
{
// GET: Kontakt
public ActionResult Index(int skolaid)
{
BazaProjekatEntities bazaKontakt = new BazaProjekatEntities();
List<Kontakt> kontakti = bazaKontakt.Kontakt.Where(x => x.SkolaID == skolaid).ToList();

Zajedno zajednomodel = new Zajedno();

List<Zajedno> kontaktiskola = kontakti.Select(x => new Zajedno{ Ime = x.Ime, KontaktID = x.KontaktID, Prezime = x.Prezime ,RadnoMesto = x.RadnoMesto, NazivSkole = x.Skola.NazivSkole, AdresaRegistracije = x.Skola.AdresaRegistracije, Opstina=x.Skola.Opstina, SkolaID = x.SkolaID}).ToList();

return View(kontaktiskola);
}
}
}

主要问题是在foreach中,我不知道如何处理,只显示一所学校,我的意思是,我根本不需要foreach,但是没有它,我不知道如何

最诚挚的问候!

1 个答案:

答案 0 :(得分:0)

您从struct Node得到什么对象?您可以调试应用程序并提供该行中的对象吗?这样一来,为您提供任何良好的解决方案就会更加容易。