一个主要的 ASP.NET 上的多个部分视图
尝试在 ASP.NET 的主页上放置强类型的部分视图,但似乎不起作用,这是我
对 ASP.NET 和部分视图的新代码。
控制器:
public ActionResult VenuePartial()
{
ViewData["Message"] = _entities.VenuePartialList();
return View();
}
存储库:
public IEnumerable<Venue> VenuePartialList()
{
var list = from s in _entities.Venue
orderby s.name ascending
select s;
return list.ToList();
}
IRepository:
IEnumerable<Venue> VenuePartialList();
索引页:
<%Html.RenderPartial("~/Views/Venue/VenuePartial.ascx");%>
请尽快提供任何帮助,我们将不胜感激 问候 T
trying to put a strongly typed partial view on a homepage in asp.net but it wont seem to work it, here is my code
new to asp.net and partial views.
Controller :
public ActionResult VenuePartial()
{
ViewData["Message"] = _entities.VenuePartialList();
return View();
}
Repository :
public IEnumerable<Venue> VenuePartialList()
{
var list = from s in _entities.Venue
orderby s.name ascending
select s;
return list.ToList();
}
IRepository :
IEnumerable<Venue> VenuePartialList();
Index Page :
<%Html.RenderPartial("~/Views/Venue/VenuePartial.ascx");%>
Any help would be grateful asap please
regards T
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您需要将模型传递给这个部分:
顺便说一下,您使用 ViewData["Message"] 来传递模型而不是使用模型和强类型视图:
然后:
这显然假设您的部分被强类型化为
IEnumerable
。如果将其输入到单个Venue
,您也可以考虑使用编辑器/显示模板。因此,在您的主视图中:以及相应的显示模板(
~/Views/Shared/DisplayTemplates/Venue.ascx
)中:现在将为模型集合的每个项目呈现显示模板。
Maybe you need to pass a model to this partial:
And by the way WTF are you using
ViewData["Message"]
to pass a model instead of using a model and a strongly typed view:and then:
This obviously assumes that your partial is strongly typed to
IEnumerable<Venue>
. If it is typed to a singleVenue
you might also consider using Editor/Display Templates. So in your main view:and in the corresponding display template (
~/Views/Shared/DisplayTemplates/Venue.ascx
):and now the display template will be rendered for each item of the model collection.