2011-09-22 66 views
2

我試圖用Html.RenderPartial,但得到的錯誤:'使用' 必須以相匹配的結束 '結束使用'

'Using' must end with a matching 'End Using'.

查看:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<mvc2Test.Models.Employee>" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
    Create 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
    <h2>Create</h2> 
    <% Html.RenderPartial("ViewUserControl1"); %> 
</asp:Content> 

管窺:

<% using (Html.BeginForm()) {%> 
    <%: Html.ValidationSummary(true) %> 

    <fieldset> 
     <legend>Fields</legend> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.EmployeeID) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBoxFor(model => model.EmployeeID) %> 
      <%: Html.ValidationMessageFor(model => model.EmployeeID) %> 
     </div> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.NationalIDNumber) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBoxFor(model => model.NationalIDNumber) %> 
      <%: Html.ValidationMessageFor(model => model.NationalIDNumber) %> 
     </div> 


     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.ModifiedDate) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBoxFor(model => model.ModifiedDate, String.Format("{0:g}", Model.ModifiedDate)) %> 
      <%: Html.ValidationMessageFor(model => model.ModifiedDate) %> 
     </div> 

     <p> 
      <input type="submit" value="Save" /> 
     </p> 
    </fieldset> 
<% } %> 

回答

2

我得到了它,我忘了這行代碼在視圖的頂部:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<mvc2Test.Models.Employee>" %> 
6

錯誤消息表明代碼被解析爲VB,而不是C#。你是否意外地爲部分視圖指定了錯誤的語言?

相關問題