Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net mvc 5如何在表头显示数据_C#_Asp.net_Asp.net Mvc_Tableheader - Fatal编程技术网

C# asp.net mvc 5如何在表头显示数据

C# asp.net mvc 5如何在表头显示数据,c#,asp.net,asp.net-mvc,tableheader,C#,Asp.net,Asp.net Mvc,Tableheader,我正在asp.NETMVC5中开发一个调度器 我是新手 我的问题是,如何从sql server数据库中显示表头数据 这是我的数据库 我希望当用户6a登录时,它在表头显示“蓝色手术”和“灰色手术” 当用户22b登录时,它会在表头显示“手术一号”和“手术二号” 这是我的桌子 这是我的查看代码 <tr> <th style="width:50px;"></th> <th i

我正在asp.NETMVC5中开发一个调度器

我是新手

我的问题是,如何从sql server数据库中显示表头数据

这是我的数据库

我希望当用户6a登录时,它在表头显示“蓝色手术”“灰色手术”

当用户22b登录时,它会在表头显示“手术一号”“手术二号”

这是我的桌子

这是我的查看代码

 <tr>
                    <th style="width:50px;"></th>

                    <th id="header1">Surgery 1</th>

                    <th id="header2">Surgery 2</th>

                    <th id="header3"></th>

                    <th id="header4"></th>

                    <th id="header5"></th>

                    <th id="header6"></th>

                </tr>
控制器中的我的索引

// GET: Schedules
    public ActionResult Index()
    {

        //var schedules = db.Schedules.Include(s => s.AspNetUser).Include(s => s.Doctor).Include(s => s.Surgery).Include(s => s.Patient);
        //return View(schedules.ToList());
        var currentUser = User.Identity.GetUserId();
        var schedule = db.Schedules.Where(x => x.ClinicName == currentUser);


        return View(schedule);

        var surgery = db.Surgeries.Where(x => x.ClinicName == currentUser);
        ViewBag.Headers = surgery.Select(s => s.SurgeryName).ToList();

    }
这可能行得通

控制器

// GET: Schedules
    public ActionResult Index()
    {

        //var schedules = db.Schedules.Include(s => s.AspNetUser).Include(s => s.Doctor).Include(s => s.Surgery).Include(s => s.Patient);
        //return View(schedules.ToList());
        var currentUser = User.Identity.GetUserId();
        var schedule = db.Schedules.Where(x => x.ClinicName == currentUser);


        return View(schedule);

        var surgery = db.Surgeries.Where(x => x.ClinicName == currentUser);
        ViewBag.Headers = surgery.Select(s => s.SurgeryName).ToList();

    }
Html


@if(ViewBag.Headers!=null&&ViewBag.Headers.Count>0){
对于(int i=0;i
这将解决空列问题,但您确实应该使用Viewmodels


@if(ViewBag.Headers!=null&&ViewBag.Headers.Count>0){
对于(int i=0;i<6;i++){
@(ViewBag.Headers.Count>i?ViewBag.Headers[i]:“”)
}
}

为什么pplz要做负面标记,我陷入了这个问题“/”应用程序中的服务器错误System.Collections.Generic.List.Count'不能像方法一样使用。详细信息:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:非invocable成员“System.Collections.Generic.List.Count”不能像方法一样使用。源错误:第75行:第76行:第77行:@if(ViewBag.Headers!=null&&ViewBag.Headers.Count()>0)第78行:{79行:for(int i=0;iViewBag.Headers = schedule.Select(s => s.SurgeryName).ToList();
<tr>
    <th style="width:50px;"></th>
    @if (ViewBag.Headers != null && ViewBag.Headers.Count > 0){
        for (int i = 0; i < ViewBag.Headers.Count; i++){
            <th id="header_@i">@ViewBag.Headers[i]</th>
        }
    }
</tr>
 <tr>
     <th style="width:50px;"></th>
     @if (ViewBag.Headers != null && ViewBag.Headers.Count > 0){
         for (int i = 0; i < 6; i++){
             <th id="header_@i">@(ViewBag.Headers.Count > i ? ViewBag.Headers[i] : "")</th>
         }
     }
 </tr>