Note that there are some explanatory texts on larger screens.

plurals
  1. POASP MVC DropDownList error "Converting to Type"
    text
    copied!<p>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:</p> <pre><code>[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); } </code></pre> <p>The error I get is: </p> <blockquote> <p>Message = "The parameter conversion from type 'System.String' to type 'ConstructionProject.Models.Status' failed because no TypeConverter can convert between these types."</p> </blockquote> <p>But like I said, the database model for the field "TypeID" and "StatusID" are identical.</p> <p>Edit:</p> <h2>DB Schema:</h2> <p><strong>Table Project</strong></p> <pre><code>ProjectID int TypeID int StatusID int Name varchar(50) Description text DateCreated datetime ClientID int Contractor int </code></pre> <p><strong>Table Status</strong></p> <pre><code>StatusID int Text varchar(50) </code></pre> <p><strong>Table Project Type</strong></p> <pre><code>TypeID int Text varchar(50) </code></pre> <p>Anyone knows what would correct the issue here?</p> <p>My View Page (after changing to StatusID):</p> <pre><code> &lt;p&gt; &lt;label for="Status"&gt;Status:&lt;/label&gt; &lt;%= Html.DropDownList("StatusID")%&gt; &lt;%= Html.ValidationMessage("StatusID", "*")%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="Types"&gt;Type:&lt;/label&gt; &lt;%= Html.DropDownList("Types")%&gt; &lt;%= Html.ValidationMessage("Types", "*")%&gt; &lt;/p&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload