0

I have two input type submit on my view.

  1. <input type="submit" name="submitbutton1" value="Save">

2.<input type="submit" name="submitbutton2" value="Process">

My view is Manage.vbhtml and in that view i have a form with the above two submit buttons.

My controller is StaffController and 'Function Manage(item as staff,submitbutton1 as string,submitbutton2 as string) as ActionResult' is associated with the above view. When i click any of the two submit buttons i should be getting the value of that button in the string parameter, but it's giving me nothing. Please help me, i want to detect which submit button was pressed. The mentioned actionresult has <HttpPost> _ in the attribute.

I have followed as per this link but still no result.

Community
  • 1
  • 1

1 Answers1

0

You can check it from FormCollection:

in Html:

<input type="submit" name="submitbutton" value="Save">
<input type="submit" name="submitbutton" value="Process">

and in Action:

[HttpPost]
public ActionResult Manage()
{

   var temp = Request.Form["submitbutton"].ToString();

   if(temp == "Save")
   {
     // save clicked
   }
   if(temp == "Process")
   {
     // Process clicked
   }

    return View();

}

or:

[HttpPost]
public ActionResult Manage(FormCollection form)
{

   var temp = form["submitbutton"].ToString();

   if(temp == "Save")
   {
     // save clicked
   }
   if(temp == "Process")
   {
     // Process clicked
   }

    return View();

}
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
  • Thanks, but still no luck. Form does not contain the key named "submitbutton". The same think works on my other controller and its method, but not on this controller and method. – Nimit Vachhani Oct 11 '14 at 04:10
  • Make sure buttons are inside form – Ehsan Sajjad Oct 11 '14 at 04:12
  • Hey dude, i think i have found the problem. Well i am passing "Staff" model to that view and it has email-id as one of the property. I have used remote validation for that property. The validation is working but it "Return Json(True, JsonRequestBehavior.AllowGet)" so when ever i click the button it sends nothing for "submitbutton". Is there any chance that i can modify my validation code ? – Nimit Vachhani Oct 11 '14 at 05:44
  • Okies figured the solution - I was supposed to change my – Nimit Vachhani Oct 11 '14 at 07:19