フォームには 4 つのボタンがあり、「送信 1」はコントローラー A を呼び出し、「送信 2」はコントローラー B を呼び出します。
同じフォームに 'Button 1' と 'Button 2' もあり、これらの検証を実行/起動したくありません。
「ボタン 1」と「ボタン 2」ではなく、「送信 1」と「送信 2」でフォームを検証するにはどうすればよいですか?
同時に、'Button 1' と 'Button 2' は別のコントローラーに送信する必要があります。どうすればこれを達成できますか?
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>
}
「Submit 1」と「Submit 2」で DataAnnotations を使用してフォームを検証したいのですが、「Button 1」をクリックすると、フィールド「Bypassid」に値があることを確認し、別のコントローラーにリダイレクトする必要があります (たとえば、. 「ボタン 2」をクリックします。何も検証せず、別のコントローラーにリダイレクトするだけです。