【发布时间】:2020-04-11 12:06:19
【问题描述】:
我需要帮助在一个视图中使用来自 2 个模型的上下文。我需要使用来自ZanrModel.cs 的ZanrID 和Ime
这里是ZanrModel.cs 代码:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace WebApplication1.Models
{
[Table("Zanr")]
public class ZanrModel
{
[Key]
public int ZanrID { get; set; }
public string Ime { get; set; }
}
}
我想在我使用 KnjigaModel.cs 的视图中使用 ZanrdID 和 Ime
@model IEnumerable<WebApplication1.Models.KnjigaModel>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<a href="/Knjiga/Create" class="btn btn-warning">Dodaj novu knjigu</a>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.InventarniBroj)
</th>
<th>
@Html.DisplayNameFor(model => model.Pisac)
</th>
<th>
@Html.DisplayNameFor(model => model.Naslov)
</th>
<th>
@Html.DisplayNameFor(model => model.GodinaIzdavanja)
</th>
<th>
@Html.DisplayNameFor(model => model.MestoIzdavanja)
</th>
<th>
</th>
<th>
</th>
<th>
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.InventarniBroj)
</td>
<td>
@Html.DisplayFor(modelItem => item.Pisac)
</td>
<td>
@Html.DisplayFor(modelItem => item.Naslov)
</td>
<td>
@Html.DisplayFor(modelItem => item.GodinaIzdavanja)
</td>
<td>
@Html.DisplayFor(modelItem => item.MestoIzdavanja)
</td>
<td>
<a href="/Knjiga/Izmeni/@item.KnjigaId" class="btn btn-warning">Edit</a>
</td>
<td>
<a href="/Knjiga/Details/@item.KnjigaId" class="btn btn-primary">Details</a>
</td>
<td>
<a href="/Knjiga/Delete/@item.KnjigaId" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</table>
是的,我想在Knjiga/Create.cshtml 中创建dropdown menu,用户可以在其中选择Zanr
他们想使用它。我有Knjiga 和Zanr 的数据库,下面是它的图片:
提前致谢!!!
【问题讨论】:
标签: c# html asp.net-mvc database