视图模型问题,“不包含定义”
我收到此错误“对象”不包含“图像”的定义,并且无法找到接受类型“对象”的第一个参数的扩展方法“图像”(您是否缺少 using 指令或程序集引用?
)索引.aspx
<div class="wrapCarousel">
<div class="Carousel">
<% foreach (var image in Model.Images){ %>
<div class="placeImages">
<img width="150px" height="150px" src="../Img/<%=image.TnImg%>" alt="<%=image.Name%>" />
<div class="imageText">
<%=image.Name%>
</div>
</div>
<% } %>
这是我的 homecontroller.cs:
public ActionResult Index()
{
ViewData["noOfPlaces"] = noOfPlaces();
ImageViewModel imageViewModel = new ImageViewModel();
imageViewModel.Images = getImages();
return View("Index", imageViewModel);
}
这是我的 Imageviewmodel.cs:
namespace laMVC.Models
{
public class ImageViewModel
{
public IList<Image> GetImages { get; set; }
public IList<Image> Images { get; set; }
public Image Image { get; set; }
}
}
为什么 index.aspx 找不到 Model.Images?
I get this error 'object' does not contain a definition for 'Images' and no extension method 'Images' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
inside my index.aspx
<div class="wrapCarousel">
<div class="Carousel">
<% foreach (var image in Model.Images){ %>
<div class="placeImages">
<img width="150px" height="150px" src="../Img/<%=image.TnImg%>" alt="<%=image.Name%>" />
<div class="imageText">
<%=image.Name%>
</div>
</div>
<% } %>
this is my homecontroller.cs:
public ActionResult Index()
{
ViewData["noOfPlaces"] = noOfPlaces();
ImageViewModel imageViewModel = new ImageViewModel();
imageViewModel.Images = getImages();
return View("Index", imageViewModel);
}
and this is my Imageviewmodel.cs:
namespace laMVC.Models
{
public class ImageViewModel
{
public IList<Image> GetImages { get; set; }
public IList<Image> Images { get; set; }
public Image Image { get; set; }
}
}
How come index.aspx can't find Model.Images?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改您的视图以继承
ViewPage
。Change your view to inherit
ViewPage<PubbaMVC.Models.ImageViewModel>
.你应该改变
你的观点
you should change
in your view to