forum

Home / DeveloperSection / Forums / viewbag in mvc 4

viewbag in mvc 4

Anonymous User210209-Oct-2014
I am using a ViewBag as my checkpoint to which partial view should I render on a certain div and here's my code.
In Controller:
[HttpPost]
        publicActionResult NewAppointment(appointment.AppointmentInformation model)
        {
            if (ViewBag.NextForm == null || ViewBag.NextForm == "undefined")
            {
                info.CustomerType = model.CustomerType;
                ViewBag.NextForm = "Information";
            }
            elseif (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";
            }
            elseif (ViewBag.NextForm == "Services")
            {
                //do nothing;
            }
            return View(info);
        }

In View:

<formmethod="post">
    <divid="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>
    <divid="ButtonArea">
        <buttonid="btnCancel">Cancel</button>
        <buttonid="btnBack">Back</button>
        <buttonid="btnNext">Next</button>
    </div>
</form>


On third click of btnNext, the @Html.Part @Html.Partial("Service") is not working. But the first two @Html.Partial is working fine.


Updated on 09-Oct-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By