简体   繁体   English

MVC帮助程序通过查找容器来插入HTML

[英]MVC helper to insert html by finding container

I have 2 custom html helpers 我有2个自定义html助手

@html.Grid(blah...).blah...
@html.Pagination()

the problem I am facing is that Pagination will depend on the data of grid, but can be before or after it is called. 我面临的问题是分页将取决于网格的数据,但是可以在调用它之前或之后。 I need them separate to allow placement of the paging content at the bottom or top of the page instead of touching the grid. 我需要将它们分开以允许将页面内容放置在页面的底部或顶部,而不是触摸网格。

so this is an example page: 所以这是一个示例页面:

@html.Pagination()
@html.Grid(blah...).blah...
@html.Pagination()

I have figured out that I can share data between Grid and Pagination if pagination is after grid, but before is still a problem. 我已经发现,如果分页在网格之后,但之前仍然是一个问题,则可以在Grid和分页之间共享数据。 I have thought of making an empty container and modifying the html output of it in Grid, but I can't seem to figure that out. 我曾想过要制作一个空容器并在Grid中修改它的html输出,但我似乎无法弄清楚。 I want it this way so that I can do this: 我想要这样,以便我可以这样做:

@html.Pagination()
@html.Grid().Columns(...).AjaxPaging();
@html.Pagination()

If it is not possible or easily done, I can settle for putting "AjaxPaging()" and the model on both of the Pagination and the Grid, but I would like the Pagination to be dummy containers and let the grid do all the work. 如果不可能或不容易完成,我可以解决将“ AjaxPaging()”和模型放在分页和网格上的问题,但是我希望分页是虚拟容器,让网格完成所有工作。

Also, Javascript is not an option, as I also want HtmlPaging (working without js enabled) for those who disable js on websites. 另外,Javascript不是一个选项,因为我也希望HtmlPaging(在不启用js的情况下工作)适合那些在网站上禁用js的用户。 I could easily do it with Ajax or JS. 我可以轻松地用Ajax或JS做到这一点。

Thanks. 谢谢。

Model example: 型号示例:

class GridModel {
  public List<GridColumn> Columns {get; set;}
  /*  rest of model, including pagination properties  */
}

Your controller would do the work of building the model object. 您的控制器将完成构建模型对象的工作。

View Code: 查看代码:

/* `model` is of type `GridModel` */

@html.Pagination(model)
@html.Grid(model)
@html.Pagination(model)

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

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