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">
<% f开发者_开发百科oreach (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?
Change your view to inherit ViewPage<PubbaMVC.Models.ImageViewModel>
.
you should change
@model IEnumerable<laMVC.Models.ImageViewModel>
in your view to
@model laMVC.Models.ImageViewModel
精彩评论