Long winded out of necessity:
I have a strongly typed MVC 4 form. The form is built dynamically depending on the current URL parameters. When the user submits the form, the form input data is posted to a controller, the controller does it's thing, then the results from the controller method need to be displayed below the form.
Specifically in my case the results are line item ticket data. The user can hit submit as many times as they want and each time the additional results from the controller are displayed on the same page below the form; Each post is an added line item. (The line items are requested/stored by a call to an external webapi, so each time a submit happens I rebuild the line items from my controller method).
What I am trying to do is not have the page refresh every time to build the form all over again while simply updating the line items below the form through an ajax call. The form is expensive to build because it also is built from an external web api call. My model is very large and has a lot of data even though the form itself isn't.
What I have attempted so far is to put the line items into a partial view, which I will update after each form submit. I'm submitting the form with jQuery and Ajax. What seems to be happening is the form is submitted, the ajax method is called, but my controller is returning the partial view and master page layout directly. It's not returning back to the jQuery call. This could be Sitefinity or it could be something I'm doing completely wrong.
What I have so far is this: http://beta.kentuckycenter.org/all-shows/jeff-beck. Click on "Buy Tickets" on this page to see form.
Submit the form (Press "GO") then the form submits and only returns the partial view.
But it should look like this (this is design only): http://www.kentuckycenter.org.staging01.spiiider.com/select-tickets.php
Sitefinity MVC widgets change the complexity for sure. My setup is Master page (Sitefinity templates are built from master pages), then default view, and partial view. I'm trying to update the partial view inside the default view.
I've tried many different ways including ajax.beginform form but I still can't seem to get a partial view to return inside a default view. I can't pass my original SelectTicketsModel data in hidden fields because some of the items are lists of other models.
Controller Actions simplified:
public ActionResult Index(string performanceID, string pageID)
{
var Model = new SelectTicketsModel();
Model = Model.GetPerformanceDetails(performanceIDnew, productionID);
return View("Default", Model);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(GetTicketsModel Model)
{
//call webapi to reserve tickets
ticketsReserved = Model.ReserveTickets(Model.PriceType, performanceID, numberOfTickets, zoneID, Model.Accessible);
if (ticketsReserved == numberOfTickets)
{
LineItemModel lineModel = new LineItemModel();
//Fill LineItemModel from webpapi
}
return PartialView("TicketList", LineItemModel);
}
public class SelectTicketsViewModel
{
public bool Results { get; set; }
public int PerformanceID { get; set; }
public Nullable<DateTime> PreSaleDateStart { get; set; }
public Nullable<DateTime> PreSaleDateEnd { get; set; }
public bool HideSYOS { get; set; }
public bool IsGeneralAdmission { get; set; }
public bool WillCallOnly { get; set; }
public bool IsOnSale { get; set; }
public bool IsSoldOut { get; set; }
public int MaxSeats { get; set; }
public int ZoneMapID { get; set; }
public string TimeSlot { get; set; }
public string Title { get; set; }
public DateTime PerformanceDate { get; set; }
public string Location { get; set; }
// Create Lists from Models below
public List<PriceZoneModel> PriceZones { get; set; }
public List<PriceTypeModel> PriceTypes { get; set; }
public List<LineItemModel> LineItems { get; set; }
}
public class PriceZoneModel
{
public int PriceZoneID { get; set; }
public string PriceZoneDescription { get; set; }
public int PriceTypeID { get; set; }
public string PriceTypeDescription { get; set; }
public decimal Price { get; set; }
public decimal BasePrice { get; set; }
public bool Available { get; set; }
public int AvailableCount { get; set; }
public int Rank { get; set; }
}
public class PriceTypeModel
{
public int PriceTypeID { get; set; }
public string PriceTypeDescription { get; set; }
public string PriceTypeShortDescription { get; set; }
public string Category { get; set; }
public bool IsDefaultPriceType { get; set; }
public bool IsPromo { get; set; }
}
public class LineItemModel
{
int id { get; set; }
bool AccessibleSeats { get; set; }
public List<SubLineItemModel> SubLineItems { get; set; }
}
public class SubLineItemModel
{
public string Section { get; set; }
public int NumberOfSeats { get; set; }
public string SeatNumber { get; set; }
public int SeatID { get; set; }
public decimal Price { get; set; }
public string PriceTypeDescription { get; set; }
}
public class GetTicketsModel
{
//Form Values needed to Reserve Tickets
public string NumberOfTickets { get; set; }
public string PriceType { get; set; }
public string ZoneID { get; set; }
public bool Accessible { get; set; }
public string PerformanceID { get; set; }
}