Here is a good way to do it:
View:
@model Testy20161006.Controllers.ResetPasswordViewModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>IndexPage2</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
@{
if (ViewBag.ShowDialog != null && ViewBag.ShowDialog == true)
{
<script type="text/javascript">
$(function () {
$("#aModal").modal('show');
})
</script>
}
}
@using (Html.BeginForm("ResetPassword", "Home"))
{
<div>
<table>
<tr>
<td>@Html.LabelFor(r => r.oldPassword)</td>
<td>@Html.TextBoxFor(r => r.oldPassword)</td>
</tr>
<tr>
<td>@Html.LabelFor(r => r.newPassword)</td>
<td>@Html.TextBoxFor(r => r.newPassword)</td>
</tr>
<tr>
<td>@Html.LabelFor(r => r.repeatNewPassword)</td>
<td>@Html.TextBoxFor(r => r.repeatNewPassword)</td>
</tr>
</table>
</div>
<input type="submit" value="submit" />
}
@*modal*@
<div class="modal fade" id="aModal" tabindex="-1" role="dialog" aria-labelledby="aModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="aModalLabel">Warning</h4>
</div>
<div class="modal-body">
Old Password, New Password, or repeat Password is empty.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>
Controller/ViewModel:
public class ResetPasswordViewModel
{
public string oldPassword { get; set; }
public string newPassword { get; set; }
public string repeatNewPassword { get; set; }
}
public class HomeController : Controller
{
[HttpPost]
public ActionResult ResetPassword(ResetPasswordViewModel resetPasswordViewModel)
{
if (String.IsNullOrEmpty(resetPasswordViewModel.oldPassword) ||
String.IsNullOrEmpty(resetPasswordViewModel.newPassword) ||
String.IsNullOrEmpty(resetPasswordViewModel.repeatNewPassword)
)
{
//show dialog
ViewBag.ShowDialog = true;
}
return View("IndexPage2", resetPasswordViewModel);
}
public ActionResult IndexPage2()
{ //start page specified in routeconfig.cs
return View();
}