'使用'必须以匹配的“结束使用”结束

时间:2011-09-22 08:22:33

标签: c# .net asp.net-mvc-2

我正在尝试使用Html.RenderPartial,但收到错误:

  

'使用'必须以匹配的“结束使用”结束。

查看:

<%@ 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 个答案:

答案 0 :(得分:6)

错误消息表明代码被解析为VB,而不是C#。您是否意外地为部分视图指定了错误的语言?

答案 1 :(得分:2)

我知道了,我忘了把这行代码放在视图之上:

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