【问题标题】:MVC Creating Infragistics grid in strongly-typed ViewMVC 在强类型视图中创建 Infragistics 网格
【发布时间】:2014-08-26 13:27:53
【问题描述】:

我有一个视图 (ViewLeads),它只有一个 Infragistics 网格已经在工作并且可以正常提取数据。我有另一个视图(UpdateLead),其中有几个文本框,当您单击特定用户时,它们会在网格中显示数据。

我想做的是将基础架构网格添加到这个新视图 (UpdateLead)。我遇到的问题是,在我的第一个视图(ViewLead)中,我的模型参考是......

@model IQueryable<LeadManagement.BusinessEntities.BusinessLead>

再往下,我的网格就像..

 @(Html.Infragistics()
            .Grid(Model)
            .ID("grid123")
            .Width("100%")
            .PrimaryKey("Lead_ID")
            .AutoGenerateColumns(false)
            .AutoGenerateLayouts(false)
            .Columns(column =>
            {


                column.For(x => x.Lead_ID).Hidden(true);
                onclick='return true;' />", "Lead_ID", "string", "3%") { Template = "<input type='checkbox' name='select'/>" });
               style='color:blue;'>${Name}</a>").HeaderText("Name").Width("10%");
                style='color:blue;'>${Name}</a>").HeaderText("Name").Width("10%");
                column.For(x => x.Name).Template("<a href='UpdateLead?id=${Lead_ID}' style='color:blue;'>${Name}</a>").HeaderText("Name").Width("10%");
                column.For(x => x.LeadCreationDate).HeaderText("Created").Width("8%");
                column.For(x => x.Source).HeaderText("Source").Width("10%");
                column.For(x => x.status).Template("<a href='#' style='color:blue;'>${status}</a>").HeaderText("Status").Width("10%");
                column.For(x => x.Note).HeaderText("Notes").Width("10%"); 
                column.For(x => x.Litigation).HeaderText("Type of Litigation").Width("12%");
                column.For(x => x.originalFirm).HeaderText("Original Firm").Width("13%");
                column.For(x => x.CurrentFirm).HeaderText("Current Firm").Width("13%");
                column.Columns.Add(new GridColumn("Accept/Deny/Transfer", "Lead_ID", "string", "18%") { Template = "<input type='image' src='/Images/Accept.jpg' height='20' width='20' onclick='return Accepted(${Lead_ID})'/>&nbsp;&nbsp;&nbsp;<input type='image' src='/Images/Reject.png' height='20' width='20' onclick='return Rejected(${Lead_ID})'/>&nbsp;&nbsp;&nbsp;<input type='image' src='/Images/Transfer.png' height='20' width='20' id='InputAssignLead' onclick='return AssignLead(${Lead_ID})'/>" });
            })

现在...

在我的另一个视图 (UpdateLead) 上,因为我有文本框和我正在填充模型参考的东西..

@model LeadManagement.BusinessEntities.BusinessLead

所以当我尝试将我的网格代码复制到这个视图时,它抱怨

.Grid(Model)

部分,说它有无效的参数,反之亦然,如果我将模型引用更改为文本框抱怨的 Iqueryable 引用。

我怎样才能将两者都放在同一页面上(文本框和网格)????我试过引用这两种模型类型,但这也不起作用。我已经坚持了几天了。提前致谢!!

【问题讨论】:

  • 您需要将 IEnumerable&lt;T&gt; 传递给 .Grid 参数 - 您应该能够使用 new List&lt;BusinessLead&gt; { Model.BusinessLead } (即一个包含 1 项的新列表) - 我假设您只想在更新页面的网格中显示一行?通常,我倾向于使用ViewModel 来支持View,而不是直接使用有问题的业务模型类型——例如我会有一个 EditBusinessLeadViewModelBusinessLead 等类型的属性,并在视图中使用它 - 这样您就可以将行为与模型数据放在一起
  • 查理,谢谢你的回复。最终,更新页面上的新网格将为选定的特定用户显示“注释”。但是是的,现在我只是想让它基本上显示所选用户的一行。所以你说的不是 .Grid(Model),而是 .Grid(new List) 之类的东西?
  • 是的,但这取决于这是否有意义 - 听起来您有两个视图,一个包含潜在客户列表,其中包含用于对潜在客户执行操作的按钮,另一个视图显示领导并允许您编辑/更新它们。在此屏幕上,您似乎想显示一个网格,其中仅包含用户在上一页中选择的线索。如果是这样,您可以将单个引线包装在集合类型中(支持IEnumerable 的东西,例如我建议的List&lt;T&gt;)并将其传递给网格。它只会包含 1 个项目,但会满足集合类型的网格需求
  • 好的,谢谢!!

标签: c# asp.net-mvc entity-framework infragistics strongly-typed-view


【解决方案1】:

如果你没有提到,可能会出现这样的问题:

@using Infragistics.Web.Mvc

您的模型如下例所示

@using IgniteUI.SamplesBrowser.Models

    @model IQueryable<IgniteUI.SamplesBrowser.Models.Northwind.Product>
<!DOCTYPE html>

<html>
<head>
    <title></title>

    <!-- Ignite UI Required Combined CSS Files -->
    <link href="http://cdn-na.infragistics.com/igniteui/2016.2/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
    <link href="http://cdn-na.infragistics.com/igniteui/2016.2/latest/css/structure/infragistics.css" rel="stylesheet" />

    <script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>

    <!-- Ignite UI Required Combined JavaScript Files -->
    <script src="http://cdn-na.infragistics.com/igniteui/2016.2/latest/js/infragistics.core.js"></script>
    <script src="http://cdn-na.infragistics.com/igniteui/2016.2/latest/js/infragistics.lob.js"></script>

</head>

<body>
        @(Html.Infragistics()
            .Grid(Model)
            .ID("grid")
            .Width("100%")
            .Height("500px")
            .PrimaryKey("ID")
            .AutoGenerateColumns(false)
            .AutoGenerateLayouts(false)
            .Columns(column =>
            {
                column.For(x => x.ProductName).HeaderText("Product Name").Width("30%");
                column.For(x => x.CategoryName).HeaderText("Category").Width("30%");
                column.For(x => x.UnitPrice).HeaderText("Unit Price").Width("20%");
                column.For(x => x.UnitsInStock).HeaderText("Units In Stock").Width("20%");
            })
            .Features(features =>
            {
                features.Sorting().Type(OpType.Remote);
                features.Paging().Type(OpType.Remote);
                features.Filtering().Type(OpType.Remote);
                features.Responsive().ColumnSettings(cs =>
                {
                    cs.ColumnSetting().ColumnKey("CategoryName").Classes("ui-hidden-phone");
                    cs.ColumnSetting().ColumnKey("UnitPrice").Classes("ui-hidden-phone ui-hidden-tablet");
                });
            })
            .DataSourceUrl(Url.Action("GetProducts"))
            .Render()
        )
    </body>
    </html>

http://www.igniteui.com/grid/_ga=1.235256967.729368916.1477415519

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多