大家好,我必须从下拉列表中获取所选值到控制器中的 post 方法中。我该怎么做
这是我的控制器
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult AddNew()
{
ViewBag.Roles = new SelectList(List(), "RoleID", "RoleName");
return View();
}
//
//Geting All Roles In a GetRoles()/
//
public List<ResourceModel> List()
{
var roles = new List<ResourceModel>();
SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True");
SqlCommand Cmd = new SqlCommand("Select GroupId,EmplopyeeRole from EmployeeGroup", conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(Cmd);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
var model = new ResourceModel();
model.RoleId = Convert.ToInt16(ds.Tables[0].Rows[i]["GroupId"]);
model.RoleName = ds.Tables[0].Rows[i]["EmplopyeeRole"].ToString();
roles.Add(model);
}
conn.Close();
return roles ;
}
//
//To perform the AddNew Logic..i.e it adds a new employee to DB/
//
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddNew(ResourceModel model)
{
// var modelList = new List<ProjectModel>();
using (SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True"))
{
conn.Open();
SqlCommand insertcommande = new SqlCommand("InsertEmplyoee", conn);
insertcommande.CommandType = CommandType.StoredProcedure;
insertcommande.Parameters.Add("@EmployeeName", SqlDbType.VarChar).Value = model.EmployeeName;
insertcommande.Parameters.Add("@EmployeeEmailId", SqlDbType.VarChar).Value = model.EmployeeEmailId;
insertcommande.Parameters.Add("@EmployeePassword", SqlDbType.VarChar).Value = model.EmployeePassword;
insertcommande.Parameters.Add("@GroupName", SqlDbType.VarChar).Value = model.RoleName;
insertcommande.ExecuteNonQuery();
}
return View();
}
现在我想在我的 postmethod 中获取选定的值@GroupName 参数...任何人都可以帮助如何做到这一点
这是我的html
<%:Html.DropDownList("Roles")%>