Here is a lesson learned which could have been avoided with more explicit instructions, re: creating partial views
when doing this refactoring.
For RSVP, the text reads:
We can do this by right-clicking on the \Views\Dinners folder and then choosing the Add->View menu command. We’ll have it take a Dinner object as its strongly-typed ViewModel. We can then copy/paste the RSVP content from our Details.aspx view into it.
To be brutally-clear, this could read:
We can do this by right-clicking on the \Views\Dinners folder and then choosing the Add->View menu command. We’ll have it take a Dinner object as its strongly-typed ViewModel, and be sure to click on the "Create a partial view (.ascx) option". We can then copy/paste the RSVP content from our Details.aspx view into it.
This is obviously a NEWB observation, but that .ascx nuance is vitally
important to actually creating a partial view. Since we created our first partial view MANY pages ago, a more explicit reminder
to select the "Create a partial view (.ascx)" option would have been very
If you (like me) do not
click on the "Create a partial view (.ascx)" option in that Create View wizard, here is what you will see when you try to run the updated app and select a dinner event to view:
MasterPage cannot be applied to this page because the control collection is read-only. If the page contains code blocks, make sure they are placed inside content controls (i.e. <asp:Content runat=server />)
The key here is the phrase "the control collection is read-only." If you then compare your "partial" pages (which were created as .asp
x, not .asc
x), you will see that your pages begin with:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NerdDinner.Models.Dinner>" %>
and that the RSVP and EditAndDeleteLinks pages in the NerdDinner 1.0.zip archive of "known-good" source code both begin with:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.Dinner>" %>
So kewl, let's just copy and paste the code from the "known-good" source code into our "partials," right?
Wrong, because our "partials" were not actually created as partials, this won't work, but the resulting error message does look less onerous:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The directive 'control' is unknown.
Line 1: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinne r.Models.Dinner>" %>
I finally completely removed my RSVP and EditAndDeleteLinks "partials," then looked more closely at the Create View wizard to notice the "Create a partial view (.ascx)
" option when I recreated each of them.
I hope others benefit from my hard-learned lesson.