在 aspx 中包含 C# 文件代码

2024-02-07

我想在我的位置执行以下代码C#页。我知道这里还有更多类似的问题,但我找不到可以帮助我的东西。但是我在第一行收到服务器错误

The server block is not well formed

代码是:

<%@using Newtonsoft.Json.Linq; %>
<%@using System; %>
<%@using Project.Models;%>
<%@using Project.Controllers;%>

WebIntegrationRestService<int,int> service= new WebIntegrationRestService<int,int>();
service.GetUserByUsername(0,1,User.Identity.Name);
UserType type = null;
if (User.Identity.IsAuthenticated)
{
    UserType type = service.GetUserByUsername(0, 1, User.Identity.Name).First().UserType;
}

if (type==UserType.TypeA)
{
    %> <li><%: Html.ActionLink("Add User ", "Create", "User")%></li> <%
}

您的代码标签不平衡。

<%@ import Newtonsoft.Json.Linq; %>
<%@ import System; %>
<%@using Project.Models;%>
<%@using Project.Controllers;%>

<%

    WebIntegrationRestService<int,int> service= new WebIntegrationRestService<int,int>();
    service.GetUserByUsername(0,1,User.Identity.Name);
    UserType type = null;
    if (User.Identity.IsAuthenticated)
    {
        UserType type = service.GetUserByUsername(0, 1, User.Identity.Name).First().UserType;
    }


    if (type==UserType.TypeA){%>

    <li><%: Html.ActionLink("Add User ", "Create", "User")%></li>        

    <% } %>

请注意,我在页面级声明和代码开头之间添加了一个开始代码标记。

我还在最后一个右大括号后添加了一个。

但你应该重新考虑一下你在做什么。当您开始将此类内容放入视图中时,您就会遇到麻烦(将内容保留在视图中的维护成本、调试问题、重复代码等)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 aspx 中包含 C# 文件代码 的相关文章

随机推荐