CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2017
    Posts
    9

    IEnumerable Does not contain a definition for Make_ID and no extension method..

    Hi all,

    I have this error in my Index.cshtml for the following code:

    PHP Code:
     @Html.DropDownListFor(=> p.Make_IDViewBag.Vehicle_Make as SelectList"Select Vehicle", new { id "ContID" }) 
    Here the model is implemented:

    PHP Code:
    @model IEnumerable<GoogleMap.Models.GoogleMapViewModel
    Here's the GoogleMapViewModel.cs code:

    PHP Code:
    using GoogleMap.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace 
    GoogleMap.Models
    {
        public class 
    GoogleMapViewModel
        
    {
            public 
    string Model_Name getset; }
            public 
    int Model_ID getset; }
            public 
    string Make_Name getset; }
            public 
    int Make_ID getset; }
            public 
    int User_ID getset; }
            public 
    Nullable<doubleMapLat getset; }
            public 
    Nullable<doubleMapLong getset; }
            public 
    virtual User User getset; }
            public 
    virtual Vehicle_Details Vehicle_Details getset; }
            public 
    virtual Vehicle_Make Vehicle_Make getset; }     
        }

    The definition is there but VS gives me the error. How do I fix it?

    Thank you!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: IEnumerable Does not contain a definition for Make_ID and no extension method..

    What does the controller method look like? Why are you passing the list in the view bag?

  3. #3
    Join Date
    Mar 2017
    Posts
    9

    Re: IEnumerable Does not contain a definition for Make_ID and no extension method..

    Quote Originally Posted by Arjay View Post
    What does the controller method look like? Why are you passing the list in the view bag?
    EDIT: FIXED everything
    Last edited by Vegeta ZA; March 27th, 2017 at 09:25 AM.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: IEnumerable Does not contain a definition for Make_ID and no extension method..

    Quote Originally Posted by Vegeta ZA View Post
    EDIT: FIXED everything
    How about you posting what you fixed so other members can benefit?

  5. #5
    Join Date
    Mar 2017
    Posts
    9

    Re: IEnumerable Does not contain a definition for Make_ID and no extension method..

    Quote Originally Posted by Arjay View Post
    How about you posting what you fixed so other members can benefit?
    Fix is here. I would post the code but this guy deserves the credit for helping me. So I have linked to his post

  6. #6
    Join Date
    Mar 2017
    Posts
    9

    Re: IEnumerable Does not contain a definition for Make_ID and no extension method..

    @Arjay

    Any idea if you can help me fix another issue that I have?

    I am trying to get the map plotting to work properly as it does not work when I add the "Vehicle_Model" table to my model.

    If I add Model_Name and Model_ID to the Vehicle_Details table and use values from there in my search, it plots the dealerships onto the map if I search for a vehicle. But that is the wrong way to do it as I need it to get the Model_Name and Model_ID from the Vehicle_Model table.

    The sql code is in a stored procedure and it worked when I use Vehicle_Details to get Model_Name and Model_ID but now when I try to get the values from Vehicle_Model it does not work although the code works as it should in sql management studio.

    The proc has this select statement which works:

    Code:
    SELECT        Vehicle_Model.Model_Name, Users.MapLat, Users.MapLong, Vehicle_Make.Make_ID, Users.User_ID
    FROM            Users INNER JOIN
                             Vehicle_Details ON Users.User_ID = Vehicle_Details.User_ID INNER JOIN
                             Vehicle_Make ON Vehicle_Details.Make_ID = Vehicle_Make.Make_ID INNER JOIN
                             Vehicle_Model ON Vehicle_Details.Model_ID = Vehicle_Model.Model_ID
    MapController.cs code:

    Code:
    using GoogleMap.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Script.Serialization;
    using System.Web.Security;
    
    namespace GoogleMap.Controllers
    {
        public class MapController : Controller
        {
    
            private GoogleMapEntities db = new GoogleMapEntities();
            //Get the select ID???
            int SelectedMake_Id = 0;
    
            // GET: Map
            public ActionResult Index()
            {
                    
                    GoogleMapEntities GE = new GoogleMapEntities();
                    List<Vehicle_Details> vehList = db.Vehicle_Details.ToList();
    
                    GoogleMapViewModel GMviewmodel = new GoogleMapViewModel();
                    List<GoogleMapViewModel> GMviewmodelList = vehList.Select(x=> new GoogleMapViewModel
                    {
    
                        Model_Name = x.Vehicle_Model.Model_Name,
                        Model_ID = x.Vehicle_Model.Model_ID,
                        Make_Name = x.Vehicle_Make.Make_Name,
                        User_ID = x.User.User_ID,
                        Make_ID = x.Vehicle_Make.Make_ID,             
                        MapLong = x.User.MapLong,
                        MapLat = x.User.MapLat
                       
                    }).ToList();
    
    
                //Populate the ViewModel
                MyPageViewModel vm = new Models.MyPageViewModel();
                vm.GoogleMapViewModelList = GMviewmodelList;
                vm.SelectedMake_Id = SelectedMake_Id;
    
                ViewBag.Vehicle_Make = new SelectList(db.Vehicle_Make, "Make_ID", "Make_Name");
                return View(vm);               
            }
    
            public JsonResult GetModById(int SelectedMake_Id)
            {
                db.Configuration.ProxyCreationEnabled = false;
                return Json(db.Vehicle_Details.Where(p => p.Make_ID == SelectedMake_Id), JsonRequestBehavior.AllowGet);
            }
    
            [HttpPost]
            public ActionResult Search(string Location)
            {
                GoogleMapEntities GE = new GoogleMapEntities();
                ////SELECT Make_Name DATA FROM DB1
                var result = GE.Vehicle_Model.Where(x => x.Model_Name.StartsWith(Location)).ToList();
                var GetVeh = (db.GetMapSearch()).ToList();
                return Json(GetVeh, JsonRequestBehavior.AllowGet);
            }
    
        }
        
    }
    The only difference that I have for the map controller code now from when it works when using Vehicle_Details table is

    Model_Name = x.Vehicle_Model.Model_Name and not Model_Name = x.Model_Name

    and Model_ID = x.Vehicle_Model.Model_ID and not Model_ID = x.Model_ID

    I also can't get the second drop down box to work but for now I need some assistance in understanding why Model_Name and Model_ID from Vehicle_Model does not work?

    Thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured