-
March 27th, 2017, 01:55 AM
#1
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 => p.Make_ID, ViewBag.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 { get; set; }
public int Model_ID { get; set; }
public string Make_Name { get; set; }
public int Make_ID { get; set; }
public int User_ID { get; set; }
public Nullable<double> MapLat { get; set; }
public Nullable<double> MapLong { get; set; }
public virtual User User { get; set; }
public virtual Vehicle_Details Vehicle_Details { get; set; }
public virtual Vehicle_Make Vehicle_Make { get; set; }
}
}
The definition is there but VS gives me the error. How do I fix it?
Thank you!
-
March 27th, 2017, 06:31 AM
#2
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?
-
March 27th, 2017, 06:39 AM
#3
Re: IEnumerable Does not contain a definition for Make_ID and no extension method..
Originally Posted by Arjay
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.
-
March 27th, 2017, 01:32 PM
#4
Re: IEnumerable Does not contain a definition for Make_ID and no extension method..
Originally Posted by Vegeta ZA
EDIT: FIXED everything
How about you posting what you fixed so other members can benefit?
-
March 28th, 2017, 01:00 AM
#5
Re: IEnumerable Does not contain a definition for Make_ID and no extension method..
Originally Posted by Arjay
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
-
March 29th, 2017, 03:46 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|