ASP Net MVC按类别列出

时间:2018-07-12 09:13:19

标签: asp.net model-view-controller ef-code-first categories product

我正在与asp.net&MVc一起开发一个销售点项目。我在选项卡菜单中列出类别,然后单击这些类别。我想在页面上列出属于该类别的产品作为部分视图。我是根据其他页面上的类别ID字段创建列表的,但无法将其作为局部视图查看。

我的控制器

public PartialViewResult Inndex(int? id)
{
if (id!=null)
{
ViewBag.Kategoriler = id;
var urunlist = ctx.Urunler.Where(x => x.KategoriID == id);
return PartialView(urunlist);
}
else
{
var urunlist = ctx.Urunler.ToList();
return PartialView(urunlist);
}
}

我的列表页面

@model IEnumerable<WebApplication6.Urunler>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Kategoriler.KategoriAdi)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Tedarikciler.SirketAdi)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.UrunAdi)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.BirimdekiMiktar)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Fiyat)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Stok)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.YeniSatis)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.EnAzYenidenSatisMikatari)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Sonlandi)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Kategoriler.KategoriAdi)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Tedarikciler.SirketAdi)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.UrunAdi)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.BirimdekiMiktar)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Fiyat)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Stok)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.YeniSatis)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.EnAzYenidenSatisMikatari)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Sonlandi)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.UrunID }) |
            @Html.ActionLink("Details", "Details", new { id=item.UrunID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.UrunID })
        </td>
    </tr>
}

</table>

我的类别页面代码

  @foreach (Kategoriler ktg in ViewBag.Kategoriler)
            {
                @*@<button class="w3-bar-item w3-button tablink" onclick="openCity(event, @ktg.KategoriID )">@ktg.KategoriAdi</button>*@
                @Html.ActionLink(ktg.KategoriAdi, "Inndex", "Urun", new { id = ktg.KategoriID }, null);

            }

0 个答案:

没有答案