How do you send a ViewModel to a Popup?

Sep 28, 2011 at 2:55 PM

I have a view where I collect data from a user, and then when I click on the link I want the popup form controller to receive that View Model and use it to show information derived from the ViewModel.

So more specifically I have a list of employees, I tick on some of them, I change the DateFrom and DateTo on my form and then the popup will show an annual leave calendar between the dates specified.

The problem is that in the code below I get the following error;

 

System.ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Employee.Master" 
Inherits="System.Web.Mvc.ViewPage<SHP.Models.TeamViewModel>" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Directors
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="EmployeeContent" runat="server">
	<% using (Html.BeginForm("Directors""Directors"FormMethod.Post, new { id = "frmDirectors" }))
	   {%>
		<%: Html.AntiForgeryToken()%>
		<%: Html.ValidationSummary(true)%>
		<fieldset>
			<legend>Directors</legend>
			<p>To view the holidays booked by the other directors, make your selection here.</p>
			<p>The holiday calendar may take time to load if you select a wide date range and/or a large number of directors</p>
			<%: Html.EditorFor(x => x.SelectedTeamMembers)%>
			<table>
				<tr>
					<td align="right">Date From</td>
					<td><%: Html.EditorFor(x => x.DateFrom) %></td>
				</tr>
				<tr>
					<td align="right">Date To</td>
					<td><%: Html.EditorFor(x => x.DateTo) %></td>
				</tr>
			</table>
			<div>
				<%:Html.MakePopupForm<SHP.Controllers.EmployeeController>(o => o.TeamCalendar(Model))%>
				<%:Html.PopupFormActionLink<SHP.Controllers.EmployeeController>(o => o.TeamCalendar(Model), "View the calendar")%>
			</div>
		</fieldset>
	<%%>
</asp:Content>
The controller ready to receive this request is so far written as follows;
        [HttpPost]
        public ActionResult TeamCalendar(TeamViewModel _tvm)
        {
            return View();
        }
and the TeamViewModel is;
    
    public class TeamViewModel
    {
        public List<Employee> TeamMembers { getset; }
        public List<SelectedTeamMember> SelectedTeamMembers { getset; }
        public DateTime? DateFrom { getset; }
        public DateTime? DateTo { getset; }
 
        public TeamViewModel(List<Employee> _teamMembers)
        {
            this.TeamMembers = _teamMembers;
            this.SelectedTeamMembers = new List<SelectedTeamMember>();
            foreach (Employee member in TeamMembers)
                SelectedTeamMembers.Add(new SelectedTeamMember(member));
        }
    }
    public class SelectedTeamMember
    {
        public bool Selected { getset; }
        public Employee Employee { getset; }
 
        public SelectedTeamMember(Employee _emp)
        {
            this.Selected = false;
            this.Employee = _emp;
        }
    }
Sep 28, 2011 at 7:51 PM

not sure, could be something not related to awesome, also I don't see a [GET] TeamCalendar action 

Sep 29, 2011 at 8:10 AM

The TeamCalendar method is in the Employee controller and looks like;

        [HttpGet]
        public ActionResult TeamCalendar(TeamViewModel _tvm)
        {
            return View();
        }
I intend to put more code in this method later.
Sep 29, 2011 at 8:12 AM

try changing your get method to something like this: TeamCalendar(int id)