В следующем примере, демонстрирующем, как создать мастер, пример ограничен двумя представлениями (FirstView и SecondView), он выполняется с помощью Блокнота и остается его тестировать.
ИндексВид
@model namespace.MyModel
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<head>
<script type="text/javascript">
$("#StartWizardButton").on("click", ShowWizard('FirstParamerValue'));
function ShowWizard(parameter) {
$.ajax({
url: '@Url.Action("FirstViewAction", "HomeController")',
type: "GET",
data:{model:JSON.Parse(@Html.Raw(Json.Encode(Model)))},
success: function (response, status, xhr) {
$('#WizardModalContainer').html(response);
$('#WizardModalDiv').modal({ backdrop: 'static', keyboard: false });
},
error: function (response) {
alert(response.responseText);
}
});
}
</script>
</head>
<body>
<button id="StartWizardButton" type="submit" data-toggle="modal">Start Wizard</button>
............
<div class="modal fade container" id="WizardModalDiv" tabindex="1" role="dialog" aria-hidden="true">
<div class="modal-dialog" id="Wizard-modal-dialog">
<div class="modal-content" id="WizardModalContent">
<div class="modal-header" id="WizardModalHeader"></div>
<div class="modal-body" id='WizardModalContainer'>
</div>
<div class="modal-footer" id="WizardModalFooter">
<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
<button type="button" onclick="ShowWizard(); return false;" class="btn btn-primary">Next</button>
</div>
</div>
</div>
</div>
</body>
Первый вид
@model namespace.FirstModel
<head>
<script type="text/javascript">
$("#SecondViewWizardButton").on("click", ShowSecondView());
function ShowSecondView() {
$.ajax({
url: '@Url.Action("SecondViewAction", "HomeController")',
type: "GET",
data:{model:JSON.Parse(@Html.Raw(Json.Encode(FirstModel)))},
success: function (response, status, xhr) {
$('#WizardModalContainer').html(response);
},
error: function (response) {
alert(response.responseText);
}
});
}
</script>
</head>
<body>
<button id="SecondViewWizardButton" type="submit" data-toggle="modal">Next</button>
............
</body>
Второй вид
@model namespace.SecondModel
<head>
<script type="text/javascript">
$("#SecondView").on("click", ShowSecondView());
function ShowSecondView() {
$.ajax({
url: '@Url.Action("SecondViewAction", "HomeController")',
type: "GET",
data:{model:JSON.Parse(@Html.Raw(Json.Encode(SecondModel)))},
success: function (response, status, xhr) {
$('#WizardModalDiv').modal('hide');
},
error: function (response) {
alert(response.responseText);
}
});
}
</script>
</head>
<body>
<button id="SecondViewWizard" type="submit" data-toggle="modal">Next</button>
............
</body>
Контроллер
public class CommandeController : Controller
{
public ActionResult Index()
{
return View("Index", MyModel);
}
public PartialViewResult FirstViewAction(MyModel model)
{
............
return PartialView("FirstView", FirstModel);
}
public PartialViewResult SecondViewAction()
{
...........
return PartialView("SecondView", SecondModel);
}
}