the GetEmpCodes is wrong. I assume the table has name and empCode columns you want to map to a select list:
public List<SelectListItem> GetEmpcodes()
{
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConVal("constring")))
{
var output = connection.Query<dynamic>("get_eCode", new { }, commandType: CommandType.StoredProcedure) // return rows
.Select(r => new SelectListItem. // map row to SelectListItem
{
Value = r.empCode, // use correct column name
Text = r.name // use correct column name
}
.ToList();
return output;
}
}
then to use:
DataAccess Db = new DataAccess();
ViewBag.codes= Db.GetEmpcodes();
the other option is to define a new class for GetEmpcode, and the current code will work:
pubic class EmpcodeModel
{
public string empCode {get; set;}
public string name {get; set;}
}
public List<EmpcodeModel> GetEmpcodes()
{
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConVal("constring")))
{
var output = connection.Query< EmpcodeModel>("get_eCode", new { }, commandType: CommandType.StoredProcedure).ToList();
return output;
}
}