none
Select Dropdown list from one DB table and Save Selected vale into another table in MVC RRS feed

  • General discussion

  • Hi,

    I have Country List in one table, Show country list in @Html.DropDownList() and After selecting one value from dropdown list send and save it to another table.

    Getting error in my code at lambda expression...

    My View:

     @Html.DropDownList(model => model.PCountryIsdCode, ViewBag.Countrycode as SelectList, "- Country Code -", new { @class = "input-group" })

    Controller:                        

     [HttpGet]
           public ActionResult RegistrationPageView()
            {
                MainDal mdal = new MainDal();

                // Country Code List
                List<CountryCodeList> list = mdal.CountryList.ToList();
                ViewBag.Countrycode = new SelectList(list, "CountryId", "CountryName ");

                return View();
            }

           [HttpPost]
           public ActionResult RegistrationPageView(RegistrationPageModel obj)
           {
               if (ModelState.IsValid)
               {
                   MainDal mad = new MainDal();
                   mad.Profile.Add(obj);
                   mad.SaveChanges();
                   return View("~/Home/Home");
               }
               else
               {
                   return View("RegistrationPageView", obj);
               }
           }

    Model class CoutryList From table Country List:

    public class CountryList
        {    
            [Key]
            public int CountryId { get; set; }

            public string CountryName { get; set; }
        }

    coming country list from above classmodel and send into below classmodel

    Model class RegistrationPageClass Save to table Profile:        

    public class RegistrationPageModel
        {           
                [Key]
                public int PId { get; set; }
               
                public string PCountryName { get; set; }      


    }

    How to Select Dropdown list from one DB table and Save Selected vale into another table.

    Thanks.


    • Edited by chandu999 Thursday, March 1, 2018 1:31 AM
    • Changed type chandu999 Friday, March 2, 2018 1:27 AM
    Wednesday, February 28, 2018 3:15 AM