Hey, I have a table with 2 fields of type int which are "StatusID" and "TypeID". TypeID works correctly but StatusID returns an error. Here's what my controller looks like:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Project project)
{
var db = new DB();
if (ModelState.IsValid)
{
try
{
db.Projects.InsertOnSubmit(project);
db.SubmitChanges();
return RedirectToAction("Index");
}
catch
{
return View(project);
}
}
ViewData["Status"] = from c in db.Status
select new SelectListItem
{
Text = c.Text,
Value = c.StatusID.ToString()
};
ViewData["Types"] = from t in db.Project_Types
select new SelectListItem
{
Text = t.Text,
Value = t.TypeID.ToString()
};
return View(project);
}
The error I get is:
Message = "The parameter conversion from type 'System.String' to type 'ConstructionProject.Models.Status' failed because no TypeConverter can convert between these types."
But like I said, the database model for the field "TypeID" and "StatusID" are identical.
Edit:
DB Schema:
Table Project
ProjectID int
TypeID int
StatusID int
Name varchar(50)
Description text
DateCreated datetime
ClientID int
Contractor int
Table Status
StatusID int
Text varchar(50)
Table Project Type
TypeID int
Text varchar(50)
Anyone knows what would correct the issue here?
My View Page (after changing to StatusID):
<p>
<label for="Status">Status:</label>
<%= Html.DropDownList("StatusID")%>
<%= Html.ValidationMessage("StatusID", "*")%>
</p>
<p>
<label for="Types">Type:</label>
<%= Html.DropDownList("Types")%>
<%= Html.ValidationMessage("Types", "*")%>
</p>