【发布时间】:2016-04-02 23:04:12
【问题描述】:
我写信给你有一个问题。我有方法:
namespace NESTshop.Infrastructure
{
public class ProductListDynamicNodeProvider : DynamicNodeProviderBase
{
private ApplicationDbContext db = new ApplicationDbContext();
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
var returnValue = new List<DynamicNode>();
foreach (Category c in db.Category)
{
DynamicNode n = new DynamicNode();
n.Title = c.CategoryTitle;
n.Key = "Kategoria_" + c.CategoryID;
returnValue.Add(n);
}
return returnValue;
}
}
它应该给我面包屑(类别列表)。
我从类别中进行了部分查看,因为我的主页上有类别列表。
型号类别:
namespace NESTshop.Models
{
public class Category
{
[Key]
public int CategoryID { get; set; }
[Display(Name ="Nazwa kategorii")]
public string CategoryTitle { get; set; }
[Display(Name ="Opis kategorii")]
public string CategoryDescription { get; set; }
[Display(Name = "Ikona Kategorii")]
public byte[] CategoryFile { get; set; }
[HiddenInput(DisplayValue = false)]
public string ImageMimeType { get; set; }
public virtual ICollection<Product> Product { get; set; }
}
}
部分查看产品类别
@using NESTshop.Models
@model List<Category>
<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more »</a></p>
</div>
<div class="row">
<div class="col-md-12">
<h2>Kategorie</h2>
<ul class="categories">
@foreach (var cat in Model)
{
<li>
<img width="30" height="30"
src="@Url.Action("GetImage", "Categories", new { cat.CategoryID })" />
@*<img src="@Url.Content("~/Content/Images/Categories/" + cat.CategoryFile)" alt="" width="30" heigth="30"/>*@
@Html.ActionLink(cat.CategoryTitle, "ProductCategory", "Products", new { CategoryID = cat.CategoryID }, null)
</li>
}
</ul>
</div>
</div>
HomeController 动作 CategoryList:
public ActionResult CategoriesList()
{
List<Category> categories = categoryRepo.GetCategory().ToList();
return PartialView(categories);
}
我在 ProductCategory 视图中显示它:
@using NESTshop.Models
@using NESTshop.Infrastructure
@model List<Product>
@{
ViewBag.Title = "ProductCategory";
}
@Html.MvcSiteMap().SiteMapPath() <--------
@if (User.IsInRole("Administrator"))
{
<p>
@Html.ActionLink("Create New", "Create")
</p>
}
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().ProductTitle)
</th>
@if (User.IsInRole("Administrator"))
{
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().ProductDescription)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().DateAdded)
</th>
}
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().ProductFile)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().Price)
</th>
@if (User.IsInRole("Administrator"))
{
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().IsBestseller)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().IsHidden)
</th>
}
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.ActionLink(Model.FirstOrDefault().ProductTitle, "Details", new { id = item.ProductID })
</td>
@if (User.IsInRole("Administrator"))
{
<td>
@Html.DisplayFor(modelItem => item.ProductDescription)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateAdded)
</td>
}
<td>
@Html.DisplayFor(modelItem => item.ProductFile)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
@if (User.IsInRole("Administrator"))
{
<td>
@Html.DisplayFor(modelItem => item.IsBestseller)
</td>
<td>
@Html.DisplayFor(modelItem => item.IsHidden)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ProductID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ProductID })
</td>
}
</tr>
}
</table>
问题是一个,当我点击主页上的类别(测试类别 1)时,我得到了很好的面包屑(开始 > 测试类别 1),但是当我点击 2、3、4.... 类别时,我有这个相同的面包屑(START > TEST CATEGORY 1)。
你能帮我解决这个问题吗?非常感谢!
【问题讨论】:
标签: c# asp.net-mvc mvcsitemapprovider