2

I am using Html.BeginForm and I have one submit and one Save as draft button both of type "Submit". I need to call Javascript validation on submit function but not for save as draft.

using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" , onsubmit = "javascript:return ValidateOnSubmit()" }))

How do I identify which button is clicked to validate only for submit?

user3064309
  • 163
  • 1
  • 3
  • 12
  • See https://stackoverflow.com/questions/19650345/mvc-razor-form-with-multiple-different-submit-buttons link – Azhar Hussain Aug 05 '19 at 09:59
  • But I want to do the validation on client side before I hit the controller. So I need to figure out which button has been clicked. – user3064309 Aug 05 '19 at 10:25
  • As mentioned in one of the answers in above link, you can check for **value** attribute on button and then perform validation accordingly. – Azhar Hussain Aug 05 '19 at 10:50

1 Answers1

0

There are many solutions for your problem :
Try to user this one :

using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {



        <input type="submit" onclick="javascript:return ValidateOnSubmit()" value="submit" /> 
        <input type="submit" value="save as draft" /> 
        }