When I select a value in the dropdownlist I get a postback and the value I selected is selected even after the postback. How do I get the default value, <--Select Project--> as selected value again after the postback? in mvc how do i do this plz help me
myn controlers like this
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult BugDetails(FormCollection form,string Projects,string Prirority,string CreatedBy,BugModel model)
{
var modelList = new List<bugmodel>();
ViewBag.Projects = new SelectList(GetProjects(), "ProjectId", "ProjectName");
ViewBag.Prirority = new SelectList(GetPriority(), "PriorityID", "Prirority");
ViewBag.CreatedBy = new SelectList(GetEmployee(), "EmployeeID", "EmployeeName");
using (SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BugtrackerNew;Data Source=SSDEV5-HP\SQLEXPRESS"))
{
SqlCommand dCmd = new SqlCommand("Filter", conn);
dCmd.CommandType = CommandType.StoredProcedure;
conn.Open();
dCmd.Parameters.Add(new SqlParameter("@ProjectID", Projects));
dCmd.Parameters.Add(new SqlParameter("@PriorityID",Prirority));
dCmd.Parameters.Add(new SqlParameter("@CreatedByID",CreatedBy));
SqlDataAdapter da = new SqlDataAdapter(dCmd);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
model.BugID = Convert.ToInt16(ds.Tables[0].Rows[i]["BugID"]);
model.Title = ds.Tables[0].Rows[i]["Title"].ToString();
model.Description = ds.Tables[0].Rows[i]["Description"].ToString();
model.ProjectName = ds.Tables[0].Rows[i]["ProjectName"].ToString();
model.Version = ds.Tables[0].Rows[i]["Version"].ToString();
model.BuildNumber = ds.Tables[0].Rows[i]["BuildNumber"].ToString();
model.Category = ds.Tables[0].Rows[i]["Category"].ToString();
model.CreatedDate = ds.Tables[0].Rows[i]["CreatedDate"].ToString();
model.Severity = ds.Tables[0].Rows[i]["Severity"].ToString();
model.Prirority = ds.Tables[0].Rows[i]["Priorities"].ToString();
model.ReleasePhase = ds.Tables[0].Rows[i]["ReleasePhase"].ToString();
model.Type = ds.Tables[0].Rows[i]["Types"].ToString();
model.CreatedBy = ds.Tables[0].Rows[i]["CreatedByID"].ToString();
model.AssignedTo = ds.Tables[0].Rows[i]["AssignedTo"].ToString();
model.Status = ds.Tables[0].Rows[i]["ToStatus"].ToString();
modelList.Add(model);
}
conn.Close();
return View(modelList);
}
}
myn view page is
using (Html.BeginForm())
{ %>
<%: Html.DropDownList("Projects", (SelectList)ViewBag.Projects)%>
<%: Html.DropDownList("Prirority", (SelectList)ViewBag.Prirority, "Select Project")%>
<%: Html.DropDownList("CreatedBy", (SelectList)ViewBag.CreatedBy, "--Select Project--")%></bugmodel>