如何在webgrid ASP.NET MVC剃刀视图中添加多个模型的数据? [英] How to add data from multiple models in a webgrid ASP.NET MVC razor view ?

查看:98
本文介绍了如何在webgrid ASP.NET MVC剃刀视图中添加多个模型的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将webgrid绑定到控制器中的单个模型数据。

但我如何将webgrid与两个模型的数据绑定。



我尝试过:



i binded webgrid with a single model data in a controller .
but how do i bind the webgrid with data of two models .

What I have tried:

@model IEnumerable<WebApplication4.Models.Register>

@{
    ViewBag.Title = "getgrid";
    WebGrid gridview = new WebGrid(Model, ajaxUpdateContainerId : "ajaxgrid");
}

<h2>getgrid</h2>

@gridview.GetHtml(columns: new[]

{
gridview.Column("ID"),
gridview.Column("FirstName"),
gridview.Column("LastName"),
gridview.Column("CH",format: @<text><input name="chkbox"
                                  type="checkbox"/></text>),
}

            )


Public ActionResult webgridview(){
list<register> li=new list<register>();
return view(li);
}





这里我把绑定寄存器类添加到网格但我想绑定其他类的详细信息.am没有找到正确答案。



here above i binded register class to grid but i want to bind other class details also .am not finding the proper answer for that.

推荐答案

您只能将单个模型传递给视图。期。故事结束。



所以,用另一个类包装模型类,然后将这个新类传递给视图。
You can only pass a single model to a view. Period. End of story.

So, wrap your model classes with another class and pass this new class to the view instead.


这篇关于如何在webgrid ASP.NET MVC剃刀视图中添加多个模型的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆