0

我们的 MVC.Net 应用程序有时会返回没有内容的标签。更具体地说, 和 之间没有任何<内容>。调出 IE-8 开发人员工具来检查返回的 HTML 会发现一个无名标记:<>及其结束标记:</>。问题是间歇性的。通常,刷新页面会清除问题。但它足够频繁,用户抱怨足够多,以至于管理层希望修复它。

出现问题时,浏览器的 HTML 源代码如下所示:

<TR sizcache="5" sizset="47">
    <TD class="label table-col-3">
        Manager:
    </TD>
    <TD class="table-col-7 last" sizcache="5" sizset="49">
        <A href="http://localhost:57791/Profile/22/Last%2c-First-MI" jQuery1359570774586="26">Last, First MI</A> 
    </TD>
</TR>
<>
  <div>
  </div>
</>

通常,浏览器的 HTML 应该如下所示:

<TR sizcache="5" sizset="47">
    <TD class="label table-col-3">
        Manager:
    </TD>
    <TD class="table-col-7 last" sizcache="5" sizset="49">
        <A href="http://localhost:57791/Profile/22/Last%2c-First-MI" jQuery1359570774586="26">Last, First MI</A> 
    </TD>
</TR>
<TR id="link-admin-assistant-28" data-update="type: 'replace-portion', dataType: 'html', target: 'link-admin-assistant-28', source: 'link-admin-assistant-28'" sizcache="5" sizset="51">
    <TD class="label table-col-3">
        Admin Assistant:
    </TD>
    <TD class="table-col-7 last" sizcache="5" sizset="53">
        <A title="Edit Administrative Assistant" href="http://localhost:57791/Person/AdminAssistantForm?clientID=28" jQuery1359570774586="27">Last2, First2 M2</A> 
    </TD>
</TR>
<TR sizcache="5" sizset="55">
    <TD class="label table-col-3">
        Type:
    </TD>
    <TD class="table-col-7 last">
        Employee 
    </TD>
</TR>

应用详情

该应用程序是使用 MVC.Net 2 构建的。我们已经升级到使用 .Net 4.0。还有大量用于客户端脚本和处理 AJAX 调用的 JQuery。

由于视图的 *.ascx 页面仅包含格式良好的 HTML5,并散布着服务器端代码片段,因此我看不到 Web 服务器如何返回“<>”标签。

问题出现在管理器和矩阵管理器 IF 块之后的某处。出现问题时,不会显示 EmployeeType。

我认为出现问题的代码部分 (基于 IE 开发工具中的可见 HTML)

<% if (managerPersonID != null && managerPersonID > 0 && !managerDisplayName.IsNullOrEmptyTrimmed()) { %>
<tr>
    <td class="label table-col-3">Manager:</td>
    <td class="table-col-7 last"><%--<a href="<%=Url.Action("Details", new { ID = manager.PersonID, Name = manager.DisplayName, GAL = "" })%>"><%=manager.DisplayName%></a>--%>
        <%= Html.ActionLink(managerDisplayName, "Details", "Person", new { ID = managerPersonID, Name = managerDisplayName.Replace(" ", "-"), GAL = "" }, new {}) %>
        <%--Matrix Manager--%>
        <% if (matrixPersonID != null && matrixPersonID > 0 && !matrixDisplayName.IsNullOrEmptyTrimmed()) { %>
            <span class="label">&#8212; Matrix:</span>
            <%--<a href="<%=Url.Action("Details", new { ID = matrixManager.PersonID, Name = matrixManager.DisplayName, GAL = "" }) %>"><%=matrixManager.DisplayName%></a>--%>
            <%= Html.ActionLink(matrixDisplayName, "Details", "Person", new { ID = matrixPersonID, Name = matrixDisplayName.Replace(" ", "-"), GAL = "" }, new {}) %>
        <% } %>
    </td>
</tr>
<% } %>

<!-- Error seems to occur somewhere after here -->

<%--Sponsoring Manager--%>
<% if (Model.SponsoringManagerPersonID != null && Model.SponsoringManagerPersonID > 0 && !Model.SponsoringManagerDisplayName.IsNullOrEmptyTrimmed()) { %>
<tr>
    <td class="label table-col-3">Sponsor:</td>
    <td class="table-col-7 last">
        <%--<a href="<%=Url.Action("Details", new { ID = Model.SponsoringManager.PersonID, Name = Model.SponsoringManager.DisplayName, GAL = "" })%>"><%=Model.SponsoringManager.DisplayName%></a>--%>
        <%= Html.ActionLink(Model.SponsoringManagerDisplayName, "Details", "Person", new { ID = Model.SponsoringManagerPersonID, Name = Model.SponsoringManagerDisplayName.Replace(" ", "-"), GAL = "" }, new {}) %>
    </td>
</tr>
<% } %>

<%-- Administrative Assistant --%>
<% Html.RenderPartial("AdminAssistant", Model.AdministrativeAssistant); %>

<%--Employee Type--%>
<tr>
    <td class="label table-col-3">Type:</td>
    <td class="table-col-7 last">
        <%= Enum.GetName(typeof(Person.PersonType), Model.EmployeeType ?? (int)Person.PersonType.Default) %>
    </td>
</tr>

 <!-- Error appears to occur somewhere before here -->

AdminAssistant 部分视图

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<AdminAssistantLink>" %>
<%
    bool IsProfileView = ((bool?)ViewData["IsProfileView"]) ?? false;
    string AdminAssistLinkID = "link-admin-assistant-" + Model.ProfilePersonID;
%>
<%-- Administrative Assistant --%>
<% if (IsProfileView && Role.AllowProfileEditSpecific(Model.ProfilePersonID)) { %>
    <%--Edit mode--%>
    <tr id="<%= AdminAssistLinkID %>" data-update="type: 'replace-portion', dataType: 'html', target: '<%= AdminAssistLinkID %>', source: '<%= AdminAssistLinkID %>'">
        <td class="label table-col-3">Admin Assistant:</td>
        <td class="table-col-7 last">
            <% if (Model.AdminAssistantPersonID != null && !Model.AdminAssistantDisplayName.IsNullOrEmptyTrimmed()) { %>
                <%-- Display currently selected assistant, with link to edit --%>
                <%= Html.ActionLink(Model.AdminAssistantDisplayName, "AdminAssistantForm", "Person", new { clientID = Model.ProfilePersonID }, new { title = "Edit Administrative Assistant" }) %>
            <% } else { %>
                <%-- Display link to add assistant --%>
                <%= Html.ActionLink("Add Administrative Assistant", "AdminAssistantForm", "Person", new { clientID = Model.ProfilePersonID }, new {title = "Add Administrative Assistant" }) %>
            <% } %>
        </td>
    </tr>
<% } else { %>
    <%--Link to Profile--%>
    <% if (Model.AdminAssistantPersonID != null && !Model.AdminAssistantDisplayName.IsNullOrEmptyTrimmed()) { %>
    <tr>
        <td class="label table-col-3">Admin Assistant:</td>
        <td class="table-col-7 last">
            <%= Html.ActionLink(Model.AdminAssistantDisplayName, "Details", "Person", new { ID = Model.AdminAssistantPersonID, Name = Model.AdminAssistantDisplayName.Replace(" ", "-"), GAL = "" }, new {}) %>
        </td>
    </tr>
    <% } %>
<% } %>
4

1 回答 1

0

也许是你的评论标签?这些是合法的剃刀语法吗?

<%--Sponsoring Manager--%>
...
<%-- Administrative Assistant --%>
...
<%--Employee Type--%>

我没有要测试的 MVC 2 站点,所以我不知道它们将如何显示。在 MVC 3 中,标签按原样显示在浏览器标记中。

于 2013-01-24T21:26:05.730 回答