You must Sign In to post a response.
  • Category: ASP.Net MVC

    How to insert dropdown and radio button value into database....


    I can insert the data into to database. But i could not know how to use the selected item from dropdown and radio button value into data base using MVC. I have the below field...

    EmpName -
    EmpDept - using DropDown
    EmpGender - using RadioButton

    could anyone help me on this
  • #767856
    You can select the dropdownlist values in JS file or CSHTML file using View Data and the details will be stored in the view data. Then you can pass this ViewData to DAL Layer from controller and store it in Database.

    @Html.DropDownList("Dr",ViewData["MyValue"] as List<SelectListItem>)


  • #767862
    Hi Gopi.

    You can use FormCollection to get the values in to your action method. Then create object based on the required properties and assign values to it and send to db logic method.
    For suppose we have customer object to store with some properties like _customerName, _gender.
    See the below lines of code for your idea.

    public ActionResult Save(FormCollection form)
    { customer objcustomer=new customer();
    objcustomer.customerName = Request.Form["cid"].ToString(); // cid is the id given for the dropdown in your cshtml.
    objcustomer.gender=Request.Form["gender"].ToString(); // gender is the id given for the dropdownlist in cshtml

    catch(Exception ex)
    return View(objcustomer);

    Sridhar Thota.
    Editor: DNS Forum.

  • Sign In to post your comments