Include C# files code at aspx

后端 未结 1 1341
礼貌的吻别
礼貌的吻别 2021-01-28 08:14

I want to execute the following code at my C# page. I know that there are more questions like this here, but I could not find something that could help me. However

相关标签:
1条回答
  • 2021-01-28 08:46

    You have unbalanced code tags.

    <%@ 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>        
    
        <% } %>
    

    Notice I added an opening code tag between your page-level declarations and the start of your code.

    I also added one after the last closing brace.

    You should re-think what you're doing though. When you start putting this sort of thing in your views you are asking for trouble (maintenence costs of keeping things in Views, debugging issues, duplicate code, etc).

    0 讨论(0)
提交回复
热议问题