locked
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.

    Thursday, March 1, 2018 1:38 AM

All replies

  • Hi,

    Welcome to MSDN forum.

    This forum is discussing Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor. Please go to Microsoft asp.net MVC forum to talk about it. Thank you for understanding.

    Best regards,

    Joyce



    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 2, 2018 5:39 AM