0

I have view with multiple submit button in ASP.NET MVC and I want validate the form using data annotations, but when user clicks on a particular button, not all submit button, validation must be performed with particular button not all button on view.

@using (Html.BeginForm("Index", "Skill", FormMethod.Post))
{
   @Html.ValidationSummary(true)
   @Html.AntiForgeryToken()
   @Html.TextBoxFor(model => model.SkillName)
   @Html.HiddenFor(model => model.SkillId)
   @Html.ValidataionSummaryFor(model => model.SkillName)

   <input type="submit" name="AddAction" value="Add" id="btnAdd"/>
   <input type="button" name="btnreset" value="Reset" />
}

I want that validation will apply only on Add button not on Next button or any button

1 Answer 1

0

You can you put "NoValidation" Buttons outside form. This will solve the issue. If you still need form data, you can serialize it via JS, like this:

$("form").serialize()

and send to server.

Sign up to request clarification or add additional context in comments.

3 Comments

but how can i decide that validation must perform on this particular button while i use $("form").serialize() please help thanks a lot
@Riyaz Well, if you really want to turn off validation with js, one of the ways here stackoverflow.com/a/7391785/1849444 or here stackoverflow.com/a/12179373/1849444
Thanks a lot,But i don't want to turn off validation but want to apply validation when user click only particular button

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.