开发者

viewmodel problem, "does not contain definition"

开发者 https://www.devze.com 2023-01-31 07:58 出处:网络
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 direct

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
0

精彩评论

暂无评论...
验证码 换一张
取 消