Home/ASP.NET Forums/General ASP.NET/MVC/How to save the selected value of dropdownlist in DB

How to save the selected value of dropdownlist in DB RSS

36 replies

Last post May 12, 2010 05:40 PM by ignatandrei

My .NET blog : http://msprogrammer.serviciipeweb.ro/ |2012 Programmer tools
  • sjfs00

    sjfs00

    0 Points

    22 Posts

    Re: How to save the selected value of dropdownlist in DB

    May 08, 2010 06:37 PM|LINK

    Thank you first of all for your interest to my case, and for being so helpful, and to be  the only one who cared so much


     I put the code you told me in the POST,

    but the :

    "

    [AcceptVerbs(HttpVerbs.Post)]
            public ActionResult Create( T_Pointage_Materiel PMACreer)
            {
                try
                {
                    
    
                    UpdateModel(PMACreer);
                    _db.AddToT_Pointage_Materiel(PMACreer);
                    _db.SaveChanges();
                    return RedirectToAction("Index");
                }
                catch
                {
    
    
                    //ModelState.AddModelError("",Ex.message);
    
    
    
    
                    var items = _db.T_imputation.Select(c => c).ToList<T_imputation>();
               
    
                    List<SelectListItem> itemsSelect = new List<SelectListItem>();
                    foreach (var item in items)
                    {
                        itemsSelect.Add(new SelectListItem
                        {
                            Value = item.id_imputation.ToString(),
                            Text = item.Libelle
                        });
                    }
                    ViewData["itemsSelect"] = itemsSelect;
    
    
    
    
    
    
                    var items2 = _db.T_Materiel.Select(c => c).ToList<T_Materiel>();
    
    
                    List<SelectListItem> items2Select = new List<SelectListItem>();
                    foreach (var item in items2)
                    {
                        items2Select.Add(new SelectListItem
                        {
                            Value = item.Num_anael.ToString(),
                            Text = item.Libelle
                        });
                    }
                    ViewData["Materiel"] = items2Select;
                    return View();
                }
            }

    sjfs00
  • sjfs00

    sjfs00

    0 Points

    22 Posts

    Re: How to save the selected value of dropdownlist in DB

    May 08, 2010 06:50 PM|LINK

    for help : i read in a forum that they put this in the post :

    var articleTypeId = Request.Form["ArticleTypeID"];
      var categoryId = Request["CategoryID"];



    to get the selected values from the view, and store them for exampl in a variable, and then put them in the model or sth like this ...

    am nnot sure of what i say ..


    Thanks !

    sjfs00
  • ignatandrei

    ignatandrei

    All-Star

    134521 Points

    21576 Posts

    Moderator

    MVP

    Re: How to save the selected value of dropdownlist in DB

    May 08, 2010 06:57 PM|LINK

    sjfs00

    but the :

    "

    ModelState.AddModelError("", Ex.message);

    You did not put, instead of

    cath

    the source :

     catch  (Ex as Exception)


    And this is the cause that you do not see any error on

    sjfs00

    when i click on "Creat" button, it relods the page with the data i entred, but , nothing happens to the DB.  

    My .NET blog : http://msprogrammer.serviciipeweb.ro/ |2012 Programmer tools
  • Prev Next
    First12 34Last

    ‹ Previous Thread|Next Thread ›