Am trying to find out why the system giving me this error in visual studio ",i populate the dropdown from the database and it has values at runtime, but when i click the submit button i get the above error, wondering what am i doing wrong here. here is my code // this is the model
public class LeaveRequest
{
public string TableTypecode { get; set; };
public string TableTypeName { get; set; };
[Display(Name = "Selected TypeCode")]
public int SelectedTableTypeCode { get; set; }
public IEnumerable<SelectListItem> LoadedTableTypeName { get; set; }
}
And below is how am fetching the data from sqlserver .. works well.
public class OpenTypeList
{
public List<LeaveRequest> OpenList()
{
string hasconnections =
ConfigurationManager.ConnectionStrings["leaveConnections"]
.ConnectionString;
List<LeaveRequest> P2 = new List<LeaveRequest>();
using (SqlConnection con = new SqlConnection(hasconnections))
using (SqlCommand cmd = new SqlCommand("ViewTypes", con))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ListName", "status");
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
LeaveRequest pom = new LeaveRequest();
pom.TableTypecode = Convert.ToString(dr.GetValue(0));
pom.TableTypeName = dr.GetString(1);
P2.Add(pom);
}
}
return P2;
}
}
}
so here i populate the list from my controller
[HttpGet]
public ActionResult LeaveRequestIndex(LeaveRequest pleave)
{
var modal = new LeaveRequest()
{
UserRoles = GetRoles(),
LoadedTableTypeName = GetTypesIdz()
};
return View(modal);
}
And lastly below is my razor code .. in the view
<div class="form-group">
@Html.LabelFor(model => model.RequestStatus)
@Html.DropDownListFor(model => model.SelectedTableTypeCode,
Model.LoadedTableTypeName, new { @class = "form-control" })
</div>
This error is generated when i click the submit button.
my post method is here...
[HttpPost]
public ActionResult LeaveRequestIndex(FormCollection fmcollection)
{
foreach (string key in fmcollection.AllKeys)
{
Response.Write("Key= " + key + " ");
Response.Write(fmcollection[key]);
Response.Write("<br/>");
}
return View();
}