简体   繁体   English

用户选择后创建动态WebGrid(MVC4)

[英]Creating a dynamic WebGrid after user selections (MVC4)

I have several web grids in a single view all working perfectly, except I now need to make one grid dynamic. 我在单个视图中有多个Web网格,它们都可以正常工作,除了现在需要使一个网格动态化。 It will populate once the user makes certain selections in ddl filters. 一旦用户在ddl过滤器中做出某些选择,它将填充。 The grid will not have a data source on pageload, I will need to send a json request to the controller but how do i create a placeholder for the grid? 网格在pageload上没有数据源,我将需要向控制器发送json请求,但是如何为网格创建占位符? I can't use @grid.GetHTML(...) 我不能使用@ grid.GetHTML(...)

because it throws an error wanting a datasource. 因为它抛出了一个错误,想要一个数据源。 I was declaring the grid with a model initially: 我最初是用模型声明网格的:

var gridHistory = new WebGrid(
    Commissions.Models.CommissionHistoryModel.getCommissionHistory());

But now that I don't know the data I need until after the user makes selections, I was going to try to do something like this (which throws an error since I'm not supplying a datasource): 但是现在我不知道需要的数据,直到用户做出选择之后,我将尝试做这样的事情(由于我没有提供数据源,这会引发错误):

var gridHistory = new WebGrid();

How can I supply a datasource when I don't have it at runtime? 在运行时没有数据源时该如何提供?

you can create partial action (with httpget attribute) returning PartialView which contains your dynamic WebGrid. 您可以创建部分操作(使用httpget属性),以返回包含动态WebGrid的PartialView。 Each time user make changes to ddl you should render you partial via $.ajax to some placeholder in main view. 每次用户对ddl进行更改时,您都应通过$ .ajax将您的内容呈现给主视图中的某个占位符。

I believe the WebGrid has a shortcoming of not doing database level paging. 我相信WebGrid的缺点是不进行数据库级分页。 If you have large amounts of data you will have some performance problems. 如果您有大量数据,则会遇到一些性能问题。

You might be interested in Dynamic MVC ( http://dynamicmvc.com ). 您可能对Dynamic MVC( http://dynamicmvc.com )感兴趣。 It will perform dynamic database level sorting, filtering, and paging. 它将执行动态数据库级别的排序,过滤和分页。 It also exposes the the html in partial views so you can customize the html directly in more of an mvc style instead of a webforms control style. 它还在部分视图中公开html,因此您可以直接使用mvc样式而不是webforms控件样式直接自定义html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM