I have 4 button on the form, 'Submit 1' calls controller A, 'Submit 2' calls controller B.
I also have 'Button 1' and 'Button 2' on the same form and I don't want validation to happen/fire for these.
How do I make 'Submit 1' and 'Submit 2' to validate the form and not the 'Button 1' and 'Button 2' ?
At the same time 'Button 1' and 'Button 2' should submit to a different controllers. How do I achieve this?
public class SampleForm
{
[Display(Name = "FName: ")]
[Required(ErrorMessage = "Enter FName")]
public string FirstName { get; set; }
[Display(Name = "LName: ")]
[Required(ErrorMessage = "Enter LName")]
public string LastName { get; set; }
[Display(Name = "Bypassid: ")]
[Required(ErrorMessage = "Enter Bypassid")]
public string Bypassid { get; set; }
}
@model SampleForm
@using (Html.BeginForm("SampleForm", "SampleController", FormMethod.Post, new { name = "frmSample", id = "frmSample" }))
{
@Html.LabelFor(model => model.FirstName)
@Html.TextBoxFor(model => model.FirstName)
@Html.ValidationMessageFor(model => model.FirstName)
@Html.LabelFor(model => model.LastName)
@Html.TextBoxFor(model => model.LastName)
@Html.ValidationMessageFor(model => model.LastName)
@Html.LabelFor(model => model.Bypassid)
@Html.TextBoxFor(model => model.Bypassid)
@Html.ValidationMessageFor(model => model.Bypassid)
<input type="submit" value="Submit 1" name="Command" />
<input type="submit" value="Submit 2" name="Command" />
<button type="button" name="Button 1" value="Button 1">Button 1</button>
<button type="button" name="Button 2" value="Button 2">Button 2</button>
}
I want 'Submit 1' and 'Submit 2' to validate the form using DataAnnotations, but when I click 'Button 1' I want to make sure there is value in the field 'Bypassid' and redirect to another controller (Say . and when I click 'Button 2' I don't to validate anything and just redirect to another controller.