包括ASPX C#文件code [英] Include C# files code at aspx

查看:125
本文介绍了包括ASPX C#文件code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 C#页执行下面的code。我知道这里有更多这样的问题,但我无法找到的东西,可以帮助我。不过,我在第一行得到一个服务器错误

 服务器块的格式不正确

在code是:

 <%@使用Newtonsoft.Json.Linq; %GT;
<%@使用系统; %GT;
<%@使用Project.Models;%GT;
<%@使用Project.Controllers;%GT;WebIntegrationRestService< INT,INT>服务=新WebIntegrationRestService< INT,INT>();
service.GetUserByUsername(0,1,User.Identity.Name);
用户类型类型= NULL;
如果(User.Identity.IsAuthenticated)
{
    用户类型类型= service.GetUserByUsername(0,1,User.Identity.Name)。首先()用户类型。
}如果(类型== UserType.TypeA)
{
    %GT; <立GT;<%:Html.ActionLink(添加用户,创建,用户)%GT;< /李> <%
}


解决方案

您有不平衡code标记。

 <%@进口Newtonsoft.Json.Linq; %GT;
<%@导入系统; %GT;
<%@使用Project.Models;%GT;
<%@使用Project.Controllers;%GT;<%    WebIntegrationRestService< INT,INT>服务=新WebIntegrationRestService< INT,INT>();
    service.GetUserByUsername(0,1,User.Identity.Name);
    用户类型类型= NULL;
    如果(User.Identity.IsAuthenticated)
    {
        用户类型类型= service.GetUserByUsername(0,1,User.Identity.Name)。首先()用户类型。
    }
    如果(类型== UserType.TypeA){%GT;    <立GT;<%:Html.ActionLink(添加用户,创建,用户)%GT;< /李>    <%}%GT;

我通知你添加页面级声明和你的code的开始之间的开口code标记。

我还添加了一个最后的大括号之后。

您应该重新思考自己在做什么,但。当你开始把这样的事情在你的意见,你是自找麻烦(保持事物意见,调试问题maintenence成本,重复code等)。

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 I get an server error at the very first line

The server block is not well formed

The code is:

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

解决方案

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).

这篇关于包括ASPX C#文件code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆