User-1714009740 posted
I have a form with 2 buttons with 2 values, Confirm and Reject, they're in same action.
When Reject button is pressed without any comment in Textarea, form will inform 'Please input this field'
When Confirm button is pressed, it doesn't need to validate, just go to the action.
This is my view
@if (Model.signingFlowViewModel.signingFlows.Count(s => s.SigningUser == User.Identity.Name && s.Status == "1") > 0)
{
using (Html.BeginForm("OvertimeSigningAsync", "Signing", FormMethod.Post,
new { onsubmit = "return confirm('Do you really want to submit the form?');" }))
{
<div class="row" style="margin-top:10px;">
<div class="col-sm-3">
<div class="form-group">
<input type="submit"
name="Sign" value="Confirm"
class="form-control btn btn-primary"
style="margin-bottom: 5px" />
<br>
<input type="submit"
name="Sign" value="Reject"
class="form-control btn btn-danger"/>
</div>
</div>
<div class="col-sm-9">
<div class="form-group">
@Html.TextBoxFor(m => m.DocNo, new { @class = "hidden" })
@Html.TextBoxFor(m => m.FlowNo, new { @class = "hidden" })
@Html.TextBoxFor(m => m.Plant, new { @class = "hidden" })
@Html.TextAreaFor(m => m.Comment, new { @class = "form-control", @required = "required" })
@Html.TextBoxFor(m => m.NewDocNo, new { @class = "hidden" })
</div>
</div>
</div>
}
}
And this is action
public async Task<ActionResult> OvertimeSigningAsync([Bind(Include = "Plant,FlowNo,DocNo,Comment,NewDocNo")]
OvertimeSigningViewModel overtimeSigningViewModel, string Sign)
{
bool result = false;
if (ModelState.IsValid && !String.IsNullOrWhiteSpace(Sign))
{
result = eISRepository.EditPurchaseRequest(
overtimeSigningViewModel.Plant,
overtimeSigningViewModel.FlowNo,
overtimeSigningViewModel.DocNo,
User.Identity.Name, Sign,
overtimeSigningViewModel.Comment,
overtimeSigningViewModel.NewDocNo);
}
}
How can I handle it?
I'm a newbie in MVC so please help
Edit: I have found the solution, I add formnovalidate
attribute to Confirm button, it'll OK