1

I have two buttons on my screen i am handling with one method : Request.Form["Approve"] becomes null as i have disabled the button, how i can get the value of Request.Form["Approve"] after disabling the button.

 @if(ViewBag.RequestAlreadyProcessed)
 { 
     <input type="submit" class="btn btn-primary btn_box" value="Approve" name="Approve" disabled="disabled" />
     <input type="submit" class="btn btn_secondary btn_box" value="Reject" name="Reject" disabled="disabled"/>
 }
 else
 {
     <input type="submit" class="btn btn-primary btn_box" value="Approve" name="Approve" />
     <input type="submit" class="btn btn_secondary btn_box" value="Reject" name="Reject" />
 }

Controller:
public async Task<ActionResult> Approve(UserApprovalModel UserApprovalModel)
{
    if (ModelState.IsValid)
    {
        if (Request.Form["Approve"] != null)
        {
            userReg.StatusCd = "APP";
        }
        else
        {
            userReg.StatusCd = "REJ";
        }
   }
   if(userReg.StatusCd == "APP")
   {
       userReg.StatusComment = "Approved";
   }
   else if(userReg.StatusCd == "REJ")
   {
      userReg.StatusComment = "Rejected";
   }
}
JP..t
  • 575
  • 1
  • 6
  • 28
Bokambo
  • 4,204
  • 27
  • 79
  • 130
  • 1
    Sadly you approach is fundamentally wrong. You should have two different controller endpoint for approval and rejection. Then bind those buttons to some client side click events which can handle the submission of form. Your controller code is doing way too much. – qamar Jun 16 '15 at 07:55
  • What is the point of 2 disabled buttons? You may as well just not include them. And as @qamar as indicated, you should have 2 different methods –  Jun 16 '15 at 08:05

1 Answers1

1

Browser do not submit disabled control as they are read only.
there is a workaround for your problem, you make the field readonly="readonly" instead of disabled="disabled"? A readonly field value will be submitted to the server while still being non-editable by the user. A SELECT tag is an exception though.

Also as a side note,

Disabled controls do not receive focus.
Disabled controls are skipped in tabbing navigation.
Disabled controls cannot be successfully posted.

(Source: https://stackoverflow.com/a/7357314/1709587.)

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Vikas Rana
  • 1,961
  • 2
  • 32
  • 49