I've been reading Scott Guthrie's post on Passing ViewData from Controllers to Views, but I don't think the lesson is clicking for my specific situation.
(Note: Due to client proprietary restrictions, I can't talk paste the actual code, so I apologize if my made up case is a bit stupid/confusing.)
I have a Controller called ScenarioController which handles the various actions revolving around the creation of a Scenario model. Various actions a user will complete are the general CRUD of Scenarios. I can create a website that does this for the Scenario model. However, I recently updated the Scenario model so that it is now made up of various sub-components (lists of other objects). The corresponding view utilizes jQuery Tabs which load partial views to, ultimately, load the forms to the various sub-component data. Unfortunately, this is where I am having trouble.
My Index page currently looks something like this:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm()) {%>
<div id="scenario">
<div id="tabs">
<ul>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div id="tab1"><% Html.RenderPartial("Tab1"); %></div>
<div id="tab2"><% Html.RenderPartial("Tab2"); %></div>
<div id="tab3"><% Html.RenderPartial("Tab3"); %></div>
</div>
<div class="submitButtons">
<input type="button" value="Save Scenario" id="SaveScenario" />
<input type="button" value="Submit Scenario" id="SubmitScenario" />
</div>
</div>
<% } %>
</asp:Content>
And the partial pages are strongly-typed to whatever they represent (primarily List<SomeObject>
).
How should the data be stored within the Scenario model? I am using a SQL database and interfacing with Entity Framework. Do I still need Properties representing the various lists of items (so I can pass ViewData using strongly typed classes), or is this something I can pass in the ViewData directly from the entity calls (and cast as needed)?