我使用的是ViewBag
爲我檢查點partial view
我應該呈現在某個div來這,這裏是我的代碼:ASP.Net MVC4剃刀ViewBag
在控制器:
[HttpPost]
public ActionResult NewAppointment(appointment.AppointmentInformation model)
{
if (ViewBag.NextForm == null || ViewBag.NextForm == "undefined")
{
info.CustomerType = model.CustomerType;
ViewBag.NextForm = "Information";
}
else if (ViewBag.NextForm == "Information")
{
info.CustomerID = String.IsNullOrEmpty(model.CustomerID) ? "" : model.CustomerID;
info.CustomerName = String.IsNullOrEmpty(model.CustomerName) ? "" : model.CustomerName;
info.CustomerCNum = String.IsNullOrEmpty(model.CustomerCNum) ? "" : model.CustomerCNum;
ViewBag.NextForm = "Services";
}
else if (ViewBag.NextForm == "Services")
{
//do nothing;
}
return View(info);
}
在查看:
<form method="post">
<div id="PartialContainer">
@if (ViewBag.NextForm == null || ViewBag.NextForm == "undefined")
{
@Html.Partial("CustomerType")
}
@if (ViewBag.NextForm == "Information")
{
@Html.Partial("GuestInformation")
}
@if (ViewBag.NextForm == "Services")
{
@Html.Partial("Service")
}
</div>
<div id="ButtonArea">
<button id="btnCancel">Cancel</button>
<button id="btnBack">Back</button>
<button id="btnNext">Next</button>
</div>
第三次點擊btnNext
,@ Html.Part @Html.Partial("Service")
不起作用。但前兩個@Html.Partial
工作正常..
我的代碼有什麼問題?
這個方法真的幫了我很多。 –