大家好,我必须从复选框中传递选中的值并从下拉菜单中选择值,
我的观点看起来像这样
Project:DropDown
-----------------------------
EmployeeNames
--------------------------
checkbox,AnilKumar
checkBox,Ghouse
this is my aspx page
<body>
<% using (Html.BeginForm())
{ %>
<%:Html.ValidationSummary(true)%>
<div></div><div style="margin:62px 0 0 207px;"><a style="color:Orange;">Projects : </a><%:Html.DropDownList("Projects")%></div>
<fieldset style="color:Orange;">
<legend>Employees</legend>
<% foreach (var item in Model)
{ %>
<div>
<%:Html.CheckBox(item.EmployeeName)%>
<%:Html.LabelForModel(item.EmployeeName)%>
</div>
<%} %>
<%} %>
</fieldset>
<p>
<input type="button" value="AssignWork" /></p>
</div>
</body>
我必须从下拉列表中获取所有选中的带有选定项目 ID 的员工姓名到我的发布方法中。我该怎么做
this is my controller
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult AssignWork()
{
ViewBag.Projects = new SelectList(GetProjects(), "ProjectId", "ProjectName");
var employee = GetEmployeeList();
return View(employee);
}
public List<ResourceModel> GetEmployeeList()
{
var EmployeeList = new List<ResourceModel>();
using (SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True"))
{
conn.Open();
SqlCommand dCmd = new SqlCommand("select EmployeId,EmployeeName from EmployeeDetails", conn);
SqlDataAdapter da = new SqlDataAdapter(dCmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
var model = new ResourceModel();
model.EmployeeId = Convert.ToInt16(ds.Tables[0].Rows[i]["EmployeId"]);
model.EmployeeName = ds.Tables[0].Rows[i]["EmployeeName"].ToString();
EmployeeList.Add(model);
}
return EmployeeList;
}
}
public List<ResourceModel> GetProjects()
{
var roles = new List<ResourceModel>();
SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True");
SqlCommand Cmd = new SqlCommand("Select ProjectId,projectName from Projects", 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.ProjectId= Convert.ToInt16(ds.Tables[0].Rows[i]["ProjectId"]);
model.ProjectName = ds.Tables[0].Rows[i]["projectName"].ToString();
roles.Add(model);
}
conn.Close();
return roles ;
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AssignWork(int projectid,string EmployeeName,FormCollection form,ResourceModel model)
{
using (SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True"))
{
conn.Open();
SqlCommand insertcommande = new SqlCommand("AssignWork", conn);
insertcommande.CommandType = CommandType.StoredProcedure;
insertcommande.Parameters.Add("@EmployeeName", SqlDbType.VarChar).Value = EmployeeName;
insertcommande.Parameters.Add("@projectId", SqlDbType.VarChar).Value = projectid;
//insertcommande.Parameters.Add("@Status", SqlDbType.VarChar).Value = model.status;
insertcommande.ExecuteNonQuery();
}
return View();
}