我試圖在另一個視圖中呈現部分ascx視圖。MVC中的ascx文件錯誤
我有但下面的錯誤在我的ASCX文件,經過一番研究,我仍然在黑暗中!:
類型或命名空間的定義,或 檔案結尾expectedend-OF-文件預計
這裏是DinnerForm.ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.Dinner>" %>
<%: Html.ValidationSummary("Please Corrent the Errors and Try Again.") %>
<fieldset>
<legend>Fields</legend>
<table border="0">
<tr>
<td><%: Html.LabelFor(m => m.Title) %></td>
<td><%: Html.TextBoxFor(m => m.Title) %></td>
<td><%: Html.ValidationMessageFor(m => m.Title, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.EventDate) %></td>
<td><%: Html.TextBoxFor(m => m.EventDate) %></td>
<td><%: Html.ValidationMessageFor(m => m.EventDate, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Description) %></td>
<td><%: Html.TextAreaFor(m => m.Description) %></td>
<td><%: Html.ValidationMessageFor(m => m.Description, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Address) %></td>
<td><%: Html.TextBoxFor(m => m.Address) %></td>
<td><%: Html.ValidationMessageFor(m => m.Address, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Country) %></td>
<td><%: Html.DropDownListFor(m => m.Country, ViewData["countries"] as SelectList)%></td>
<td><%: Html.ValidationMessageFor(m => m.Country, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.ContactPhone) %></td>
<td><%: Html.TextBoxFor(m => m.ContactPhone) %></td>
<td><%: Html.ValidationMessageFor(m => m.ContactPhone, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Latitude) %></td>
<td><%: Html.TextBoxFor(m => m.Latitude) %></td>
<td><%: Html.ValidationMessageFor(m => m.Latitude, "*") %></td>
</tr>
<tr>
<td><%: Html.LabelFor(m => m.Longitude) %></td>
<td><%: Html.TextBoxFor(m => m.Longitude) %></td>
<td><%: Html.ValidationMessageFor(m => m.Longitude, "*") %></td>
</tr>
<tr>
<td><input type ="submit" value="Save" /></td>
</tr>
</table>
</fieldset>
<% } %>
的代碼,這裏是我如何在一個名爲文件中使用它的一個示例create.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NerdDinner.Models.Dinner>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Host a Dinner
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Host a Dinner</h2>
<% Html.RenderPartial("DinnerForm"); %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
謝謝你,我應該看到那個!一旦時間限制到達,我會將其標記爲正確答案:) – 109221793 2010-10-24 22:05:22
@TaraWalsh - 將代碼移動到ascx文件時,忘記複製它並不難。我昨天剛剛完成了NerdDinner的書,所以仍然有新的記憶:) – Marko 2010-10-24 22:13:31