title: Save dropdownlist state and Radio Button state after form submit in mvc 4 ASP.net
body: <p>I am using Dropdownlist, Radiobutton, Textbox and Radio Buttons in single form. I used <code>RequiredIf</code> validators. When i submit the form, validators works but the dropdowmlist and radio button states will change. I need selected value does'nt to be changed after Submit .How to i do this My Code is.</p>
  
  <p><strong>View:</strong></p>
  
  <pre><code>    @*DropDownlist*@
  
   &lt;select id="Cust_Id" name="Cust_Id" class="dropdownlist"&gt; &lt;/select&gt;
  
      @*RadioButton*@
  
  &lt;input name="Pay_Mode1" value="false" onclick="chMd()" type="radio"
  checked="checked" /&gt;Cash &lt;input name="Pay_Mode1" onclick="chMd()"
  type="radio" value="true"  /&gt;Cheque
  
  
      @*Grid*@
  
   &lt;div id="divgrid" style="margin-top: 15px;"&gt;
                          @{
                              var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5, selectionFieldName: "selectedRow",
  ajaxUpdateContainerId: "gridContent");
                              grid.Pager(WebGridPagerModes.NextPrevious);}
                          &lt;div id="gridContent"&gt;
                              @grid.GetHtml(
                                  tableStyle: "webgrid-table",
                                  headerStyle: "webgrid-header",
                                  footerStyle: "webgrid-footer",
                                  alternatingRowStyle: "webgrid-alternating-row",
                                  selectedRowStyle: "webgrid-selected-row",
                                  rowStyle: "webgrid-row-style",
                                  columns: grid.Columns(
                                      grid.Column("Id", "ID", style: "id"),
                                      grid.Column("Cust_Name", "Cust Name", style: "PName"),
                                      grid.Column("Pay_Amount", "Pay_Amount", style: "ICode"),
                                      grid.Column("Pay_Mode", "Pay_Mode", style: "IName"),
                                      grid.Column("Bank_Name", "Bank_Name", style: "Weight"),
                                      grid.Column("Bank_Address", " Bank_Address", style: "MakingCharge"),
                                      grid.Column("ChequeNo", "ChequeNo", style: "Certification"),
                                      grid.Column("Cheque_Date", " Cheque_Date", style: "Price"),
                                      grid.Column(header: "Delete", format: @&lt;text&gt;&lt;a href="@Url.Action("DeleteReceipt", "Admin", new { Id
  = item.ID })" onclick="javascript:return confirm('Are you sure you'd like to delete this product?');"&gt;&lt;img
                                          src="../Images/delete.png" alt='Delete' /&gt;&lt;/a&gt;&lt;/text&gt;)
                              ))
                              @if (grid.HasSelection)
                              {
                                  Receipt = (JewellaryWeb.Models.Receipt)grid.Rows[grid.SelectedIndex].Value;
                                  &lt;b&gt;Id&lt;/b&gt; @Receipt.Id&lt;br /&gt;
                                  &lt;b&gt;Code&lt;/b&gt; @Receipt.Cust_Name&lt;br /&gt;
                                  &lt;b&gt;Item_Code&lt;/b&gt; @Receipt.Pay_Amount&lt;br /&gt;
                                  &lt;b&gt;Item_Name&lt;/b&gt; @Receipt.Pay_Mode&lt;br /&gt;
                                  &lt;b&gt;Weight&lt;/b&gt; @Receipt.Bank_Name&lt;br /&gt;
                                  &lt;b&gt;Making_Charge&lt;/b&gt; @Receipt.Bank_Address&lt;br /&gt;
                                  &lt;b&gt;Certification&lt;/b&gt; @Receipt.ChequeNo&lt;br /&gt;
                                  &lt;b&gt;Price&lt;/b&gt; @Receipt.Cheque_Date&lt;br /&gt;
                              }
                          &lt;/div&gt;
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>[HttpPost]
          public ActionResult ReceiptMaster(Receipt model, string command)
          {
              Receipt Receipt = new Models.Receipt();
  
              if (command == "Sumbit")
              {
                  int Id = 0;
                  if (model.Pay_Mode == "C")
                  {
                      model.ChequeNo = "";
                      model.Cheque_Date = ("1/1/1753 12:00:00 AM");
                      model.Bank_Name = "";
                      model.Bank_Address = "";
                  }
  
                  if (ModelState.IsValid)
                  {
                      Id = Receipt.SaveReceipt(model.Id, model.Cust_Id, model.Pay_Amount, model.Pay_Mode, model.Bank_Name, model.Bank_Address, model.ChequeNo, model.Cheque_Date);
                      if (Id &gt; 0)
                      {
                          ViewData["Success"] = "Product was saved successfully.";
                          ViewData["ControlView"] = 1;
                          //ObservableCollection&lt;Receipt&gt; ReceiptList = new ObservableCollection&lt;Receipt&gt;();
                          model.ReceiptList = Receipt.GetReceiptList();// model.ReceiptList is your model property
                          return View(model.ReceiptList);
  
                      }
                     // ObservableCollection&lt;Receipt&gt; ReceiptList = new ObservableCollection&lt;Receipt&gt;();
                      model.ReceiptList = Receipt.GetReceiptList();// model.ReceiptList is your model property
                      return View(model.ReceiptList);
                  }
                  model.ReceiptList = Receipt.GetReceiptList();// model.ReceiptList is your model property
                  return View(model.ReceiptList);
                  //ObservableCollection&lt;Receipt&gt; ReceiptList = new ObservableCollection&lt;Receipt&gt;();
                  //ReceiptList = Receipt.GetReceiptList();
                  //return View(ReceiptList);
              }
  
              //ObservableCollection&lt;Receipt&gt; ReceiptList = new ObservableCollection&lt;Receipt&gt;();
              model.ReceiptList = Receipt.GetReceiptList();// model.ReceiptList is your model property
              return View(model.ReceiptList);
  
          }
  </code></pre>
  
  <p><strong>Model:</strong></p>
  
  <pre><code>#region[Public Properties]
  
          public ObservableCollection&lt;Receipt&gt; ReceiptList { get; set; }
  
          DataAccessLayer objDAL = new DataAccessLayer();
  
          [DisplayFormat(ConvertEmptyStringToNull = false)]
          public Int32 Id { get; set; }
  
          [Required(ErrorMessage = "Please Select the Name")]
          public Int32 Cust_Id { get; set; }
          public string Name { get; set; }
          public string Cust_Name { get; set; }
          public string Date { get; set; }
  
          [Required(ErrorMessage = "*")]
          [StringLength(10, ErrorMessage = "Maximum {1} characters exceeded")]
          [RegularExpression(@"[0-9]*\.?[0-9]+", ErrorMessage = "{0} must be a Number.")]
          public string Pay_Amount { get; set; }
  
  
          [StringLength(10, ErrorMessage = "Maximum {1} characters exceeded")]
          public string Credit { get; set; }
  
  
          [StringLength(10, ErrorMessage = "Maximum {1} characters exceeded")]
          public string Pay_Mode { get; set; }
  
          public bool Pay_Mode1 { get; set; }
  
          public bool IsChequeRequired
          {
              get
              {
                  return Pay_Mode1;
              }
          }
  
  
  
          [RequiredIf("IsChequeRequired", true, ErrorMessage = "You must enter Bank Name !")]
          [StringLength(10, ErrorMessage = "Maximum {1} characters exceeded")]
          public string Bank_Name { get; set; }
  
          [RequiredIf("IsChequeRequired", true, ErrorMessage = "You must enter Bank Address  !")]
          //[RequiredIf("IsChequeRequired", true, ErrorMessage = "You must explain any \"Yes\" answers!")]
          [StringLength(20, ErrorMessage = "Maximum {1} characters exceeded")]
          public string Bank_Address { get; set; }
  
          //[Required(ErrorMessage = "*")]
          [RequiredIf("IsChequeRequired", true, ErrorMessage = "You must enter ChequeNo  !")]
          [StringLength(20, ErrorMessage = "Maximum {1} characters exceeded")]
          public string ChequeNo { get; set; }
  
          // [Required(ErrorMessage = "*")]
          [RequiredIf("IsChequeRequired", true, ErrorMessage = "You must enter Cheque Date !")]
          [StringLength(10, ErrorMessage = "Maximum {1} characters exceeded")]
          public string Cheque_Date { get; set; }
  
          //[RequiredIf("IsChequeRequired", true, ErrorMessage = "You must enter Cheque Date !")]
          //[StringLength(20, ErrorMessage = "Maximum {1} characters exceeded")]
          public string Credited { get; set; }
  
          public SelectList Ddl { get; set; }
  
          public List&lt;SelectListItem&gt; SelectedValue { get; set; }
  
           DataTable dt = new DataTable(); 
  
  
  #endregion[Public Properties]
  </code></pre>