Insert Data Of RaddioButton in DataBase and Get Data From DataBase in RadioButton

 Insert Data in DataBase 

Controller

 [HttpPost]
        public ActionResult Create(Final_Form model, bool Csharp, bool Fsharp, bool JAVA, bool php)
        {
            Final_Form final_Form = new Final_Form();
            final_Form.Intrested_C_ = (Csharp==true)? true:false;
            final_Form.Intrested_F_ = (Fsharp==true)? true:false;
            final_Form.Intrested_JAVA = (JAVA==true)?true:false;
            final_Form.Intrested_PHP = (php==true)?true:false;
            final_Form.Gender = model.Gender;//radioButton 
            _context.Final_Form.Add(final_Form);
            _context.SaveChanges();
            return RedirectToAction("index");
        }

View


 <div class="form-group">
        <label class="control-label col-md-2">
            Gender
        </label>
        <div class=" col-md-10">
            <label class="radio-inline">
                @Html.RadioButtonFor(model => model.Gender,"Male", new { @name = "Gender" })
                Male
            </label>
            <label class="radio-inline">
                @Html.RadioButtonFor(model => model.Gender,"Female  ", new { @name = "Gender" })
                Female
            </label>
        </div>
    </div>

GetData From Database in RaddioButton

Controller


  [HttpGet]
        public ActionResult Edit(int id)
        {
            var result = _context.Final_Form.Find(id);
            result.Intrested_C_ = (result.Intrested_C_ == null) ? false : result.Intrested_C_;
            result.Intrested_F_ = (result.Intrested_F_ == null) ? false : result.Intrested_F_;
            result.Intrested_JAVA = (result.Intrested_JAVA == null) ? false : result.Intrested_JAVA;
            result.Intrested_PHP = (result.Intrested_PHP == null) ? false : result.Intrested_PHP;
            
            
            return View( result);
        }

 [HttpPost]
        public ActionResult Edit(Final_Form final_Form, bool Csharp, bool Fsharp, bool JAVA, bool php)
        {
            Final_Form obj = new Final_Form();
            final_Form.Intrested_C_ = (Csharp == true) ? true : false;
            final_Form.Intrested_F_ = (Fsharp == true) ? true : false;
            final_Form.Intrested_JAVA = (JAVA == true) ? true : false;
            final_Form.Intrested_PHP = (php == true) ? true : false;
            final_Form.Gender = final_Form.Gender;
            _context.Entry(final_Form).State = EntityState.Modified;
            _context.SaveChanges();
            return RedirectToAction("index");
        }

View

  <div class="form-group">
                <div class="control-label col-md-2">
                    Gender
                </div>
                <div class="col-lg-10">
                    <label class="radio-inline">
                        @if (Model.Gender.ToString() == "Male".ToString())
                        {
                            <input type="radio" value="Male" id="Gender" name="Gender" checked />

                            <lable> Male </lable>
                        }
                        else
                        {
                            <input type="radio" value="Male" id="Gender" name="Gender" />
                            <lable>Male</lable>
                        }
                    </label>

                    <label class="radio-inline">
                        @{
                          
                            if (Model.Gender.ToString() == "Male".ToString())
                            {

                                <input type="radio" value="Female" id="Gender" name="Gender" />
                                <lable>Female</lable>
                            }
                            else
                            {
                                <input type="radio" value="Female" id="Gender" name="Gender" checked />
                                <lable>Female</lable>
                            }
                        }
                    </label>
                </div>
            </div>

Comments

Popular posts from this blog

Search Record From Table Using jQuery in Asp.net core MVC

How To insert Radio Button Data in DataBase -- MVC

Toolbox Webparts Controls