This is my whole error:
The model item passed into the dictionary is of type 'System.Data.Entity.DbSet`1[application.Models.model]', but this dictionary requires a model item of type 'application.Models.TABLE1'.
My view:
@model application.Models.TABLE1
@{
ViewBag.Title = "Update";
}
<h2>Update</h2>
My controller logic for the view:
//GET: /TABLE1/Update/
public ActionResult Update(string id)
{
IEnumerable<TABLE2> table2 = db.TABLE2;
IEnumerable<TABLE1> table1 = db.TABLE1;
string context = "Data Source=******;Initial Catalog=*******;User ID=******;Password=*****";
foreach (var row in table1)
{
string strAddr = row.ADDRESS1 + "+" + row.CITY + "+" + row.ST + "+" + row.ZIP + "+" + row.COUNTRY;
GoogleMapsDll.GeoResponse myCoordenates = new GoogleMapsDll.GeoResponse();
myCoordenates = GoogleMapsDll.GoogleMaps.GetGeoCodedResults(strAddr);
if (myCoordenates.Results != null && myCoordenates.Results.Length > 3)
{
string strLat = myCoordenates.Results[3].Geometry.Location.Lat.ToString();
string strLong = myCoordenates.Results[3].Geometry.Location.Lng.ToString();
using (SqlConnection myConnection = new SqlConnection(context))
{
myConnection.Open();
string strQueryUpdate = "UPDATE TABLE1 SET Lat = '" + strLat + "' , Lng = '" + strLong + "'" + "WHERE ID = '" + row.ID + "' ";
SqlCommand myCommandUpdate = new SqlCommand(strQueryUpdate, myConnection);
myCommandUpdate.ExecuteNonQuery();
}
}
}
return View(table2);
}
I have searched stack overflow, and found many answers regarding similar errors, but i cannot seem to find one that fits mine. I am not sure where or why a different model item is passed into the dictionary. Any suggestions or answers as to were my problem may be occurring or how it may be fixed would be helpful. If any more information would be helpful just ask and I will include it.
You need to change your model type in the view to match what you are passing as the model.
In your Controller, you have
but in your view you have
You either need to pass a single TABLE1 as your model into
View(..)
or change your view's model to be(The Dictionary the error is referring to is the ViewData dictionary)