I am working on a project which is on MVC, I have two buttons for a single form, on clicking first button,I am performing some action and showing a grid, a textbox and other button.
This is my View
<pre lang="HTML">@using (Html.BeginForm("Index","Home",FormMethod.Post))
{
@Html.LabelFor(model => model.Name)
@Html.TextBoxFor(model => model.Name , new { @class = "form-control" , @id = "txtbillingamount" })
@Html.LabelFor(model => model.Amount)
@Html.TextBoxFor(model => model.Amount , new { @class = "form-control" , @id = "txtbillingamount" })
<button type="submit" name="command" value="request" >Next</button>
@if (Model != null)
{
<table class="table table-hover table-bordered table-striped">
<thead class="hbl-thead">
<tr>
<th> Title</th>
<th> Number</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>@Html.DisplayFor(model => model.ToAccountTitle)@Html.HiddenFor(model => model.ToAccountTitle) </td>
<td>@Html.DisplayFor(model => model.RecieverMobileNumber)@Html.HiddenFor(model => model.RecieverMobileNumber)</td>
<td>@Html.DisplayFor(model => model.Amount)@Html.HiddenFor(model => model.Amount)</td>
</tr>
</tbody>
</table>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="form-group input-group-sm">
@Html.LabelFor(model => model.PIN)
@Html.PasswordFor(model => model.PIN , new { @class = "form-control" })
</div>
<button type="submit" name="command" value="payment">Submit</button>
</div>
}
}
And this is my controller
public ActionResult Index(MyModel model , string command){
if (ModelState.IsValid)
{
if (command == "request")
{
}
else if (command == "payment")
{
}
}
return View(model);
}
The problem I am facing is,if ModelState.IsValid fails,its returning view with data filled in table, so it is showing the Pin text box and validating it on button Next click.
What I have tried:
I have to use post back on next button instead of ajax call