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?

3
  • See stackoverflow.com/questions/19650345/… link Commented Aug 5, 2019 at 9: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. Commented Aug 5, 2019 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. Commented Aug 5, 2019 at 10:50

1 Answer 1

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" /> 
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.