Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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
Asp.net mvc 使用MVC Razor@foreach查看多个剑道网格_Asp.net Mvc_Kendo Grid_Kendo Asp.net Mvc - Fatal编程技术网

Asp.net mvc 使用MVC Razor@foreach查看多个剑道网格

Asp.net mvc 使用MVC Razor@foreach查看多个剑道网格,asp.net-mvc,kendo-grid,kendo-asp.net-mvc,Asp.net Mvc,Kendo Grid,Kendo Asp.net Mvc,是否可以使用MVC Razor@foreach创建多个剑道网格 我已经尝试了以下内容,但视图中没有呈现任何内容,看起来数据是正确的,因为我可以在脚本中看到正确的JSON数据,但没有显示网格 @using Kendo.Mvc.UI @model ProjectMVC.Models.IndexViewModel @{ ViewData["Heading"] = "Index"; } <h2>Index</h2> <p> <a asp-a

是否可以使用MVC Razor@foreach创建多个剑道网格

我已经尝试了以下内容,但视图中没有呈现任何内容,看起来数据是正确的,因为我可以在脚本中看到正确的JSON数据,但没有显示网格

@using Kendo.Mvc.UI
@model ProjectMVC.Models.IndexViewModel

@{
    ViewData["Heading"] = "Index";
}

<h2>Index</h2>

<p>
    <a asp-action="Create">Create New</a>
</p>
@{
    int gridIndex = 0;
    foreach (var Heading in Model.Headings)
    {
        gridIndex++;
        var Groups = Model.Groups.Where(x => x.Group == Heading);
        tblGroups Group = Model.Groups.Where(x => x.Group == Heading).First();



        @(Html.Kendo().Grid(Groups)
                .Name($"grid{gridIndex}")
                .Columns(columns =>
                {
                    columns.Bound(c => c.Date).Width(140);
                    columns.Bound(c => c.User).Width(190);
                    columns.Bound(c => c.Category);
                    columns.Bound(c => c.Group).Width(110);
                })
                .Pageable()
                .Filterable()
                .Scrollable()
        )

    }
 }
@使用Kendo.Mvc.UI
@模型项目mvc.Models.IndexViewModel
@{
ViewData[“标题”]=“索引”;
}
指数

创造新的

@{ int gridIndex=0; foreach(模型中的var标题。标题) { gridIndex++; 变量组=Model.Groups.Where(x=>x.Groups==标题); tblGroups Group=Model.Groups.Where(x=>x.Group==Heading.First(); @(Html.Kendo().Grid(组) .Name($“grid{gridIndex}”) .列(列=> { columns.Bound(c=>c.Date).Width(140); columns.Bound(c=>c.User).Width(190); columns.Bound(c=>c.Category); columns.Bound(c=>c.Group).Width(110); }) .Pageable() .可过滤() .Scrollable() ) } }
下面的代码确实可以使用而不是Html.Kendo().Grid来工作,但是我无法使用Kendo网格而不是表来重新创建它。有人能指出我哪里出了问题吗

具体来说,这就是aspnet核心mvc

型号:

public class tblGroups
{

    [Key]
    public int ID { get; set; }
    public DateTime Date { get; set; }
    public string User { get; set; }
    public string Category { get; set; }
    public string Group { get; set; } //<<Want separate tables split by this field
}

public class IndexViewModel
{
    public List<tblGroups> Groups { get; set; }
    public List<string> Headings { get; set; }

    Public IndexViewModel()
    {
        Groups = new List<tblGroups>();
        Headings = new List<string>();
    }
}
公共类tblGroups
{
[关键]
公共int ID{get;set;}
公共日期时间日期{get;set;}
公共字符串用户{get;set;}
公共字符串类别{get;set;}
公共字符串组{get;set;}//x.Prodcut==Heading);
@Html.DisplayNameFor(model=>Group.Date)
@DisplayNameFor(model=>Group.User)
@DisplayNameFor(model=>Group.Category)
@DisplayNameFor(model=>Group.Group)
@foreach(组中的变量项)
{
@DisplayFor(modelItem=>item.Date)
@DisplayFor(modelItem=>item.User)
@DisplayFor(modelItem=>item.Category)
@DisplayFor(modelItem=>item.Group)
}
}
}
控制器:

public class tblGroupsController : Controller
{
    public async Task<IActionResult> Index()
    {
        var allGroups = await _context.tblGroups.ToListAsync();
        var Headings = allGroups.Select(x => x.Group).Distinct();

        var model = new Models.IndexViewModel()
        {
            Groups = allGroups,
            Headings = Headings
        };

        return View(model);
    }
}
公共类tblGroupsController:控制器
{
公共异步任务索引()
{
var allGroups=wait_context.tblGroups.ToListAsync();
var headers=allGroups.Select(x=>x.Group.Distinct();
var model=新模型。IndexViewModel()
{
组=所有组,
标题=标题
};
返回视图(模型);
}
}

为了多次使用同一部分视图,网格ID应该是唯一的,因此在部分视图数据中传递ID是一种可能的解决方案。我在PartialView中多次使用同一网格,通过这些参数传递一些参数并检索不同的数据,如下所示:

查看:

和检索传入的值:

@{
    string valuePassedIn = this.ViewData.ContainsKey("VariableName") ? 
        this.ViewData["VariableName"].ToString() : string.Empty;
}

希望这有帮助…

谢谢,你是如何在控制器中将表拆分为不同的视图的?我使用这种方法是为了在同一个视图上多次使用相同的剑道网格和不同的参数。我想创建多个网格(所有相同的列和布局)但不同的数据在单个表中按列的值进行拆分。本例如何按“新问题”、“活动问题”和“关注问题”拆分数据?
<div class="row">
    <div class="col-lg-6">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title" id="panel-title">New Issues<a href="#panel-title"></a></h3>
            </div>
            <div>
                @Html.Partial("_List", new ViewDataDictionary { { "name", "grid-all-issues" }, { "style", "border:none; height:622px;" }, { "pageSize", "25" } })
            </div>
        </div>
    </div>

    <div class="col-lg-6">
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title" id="panel-title">Active Issues<a href="#panel-title"></a></h3>
                    </div>
                    <div>
                        @Html.Partial("_List", new ViewDataDictionary { { "name", "grid-waiting-issues" }, { "style", "border:none; height:273px;" }, { "pageSize", "10" } })
                    </div>
                </div>
            </div>
            <div class="col-lg-12 top-10">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title" id="panel-title">Watched Issues<a href="#panel-title"></a></h3>
                    </div>
                    <div>
                        @Html.Partial("_List", new ViewDataDictionary { { "name", "grid-watched-issues" }, { "style", "border:none; height:273px;" }, { "pageSize", "10" } })
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
@(Html.Kendo().Grid<Models.ViewModel>()
      .HtmlAttributes(new { style = @ViewData["style"].ToString() })
      .Name(@ViewData["name"].ToString())
      //...
      .Columns(columns =>
      {          
          columns.Bound(m => m.Key).Title("Issue No");        
      })          
      .DataSource(dataSource => dataSource
          .Ajax()
          .PageSize(Convert.ToInt32(@ViewData["pageSize"]))
      )
)
@Html.Partial("~/PathToYourView.cshtml", null, new ViewDataDictionary { { "VariableName", "some value" } })
@{
    string valuePassedIn = this.ViewData.ContainsKey("VariableName") ? 
        this.ViewData["VariableName"].ToString() : string.Empty;
}