ASP .net Dropdown list not saving the selected value to database
        Posted  
        
            by user326010
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user326010
        
        
        
        Published on 2010-05-03T09:49:49Z
        Indexed on 
            2010/05/03
            10:08 UTC
        
        
        Read the original article
        Hit count: 361
        
Hi
In the following code i want to save the value selected by user from drop downlist into database. but whatever value is selected by user, first value of dropdown lsit is saved to database
View
<% =Html.DropDownList("lstUsertype", (SelectList)ViewData["UserTypeID"])%>
Controller
public ActionResult CreateUser()
        {
            UmUser _UmUser = new UmUser();
            UMRepository _UMRepository = new UMRepository();
            EvoLetDataContext db = new EvoLetDataContext();
            ViewData["UserTypeID"] = new SelectList(_UMRepository.FillUserTypes(), "UserTypeID", "UserType",2);
            return View(_UmUser);
    }
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult CreateUser(UmUser _umUser)
    {
        //try
        //{
            if (ModelState.IsValid)
            {
                //try
                //{
                    UserRepository _UserRepository = new UserRepository();
                    _UserRepository.Add(_umUser);
                    _UserRepository.Save();
                    return RedirectToAction("Details", new { id = _umUser.UserID });
                /*}
                catch
                {
                    ModelState.AddModelErrors(_umUser.GetRuleViolations());
                }*/
            }
            return View();
        //}
        /*catch
        {
            return View();
        }*/
    }
© Stack Overflow or respective owner