在MVC 4.0中替换嵌套的转发器 [英] Replacement of nested repeater in MVC 4.0

查看:51
本文介绍了在MVC 4.0中替换嵌套的转发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想在MVC 4.0中替换嵌套的转发器。

实际上,我的场景是这样的:



*我有一个表tbl_class,其中包含所有类的记录(id,class,floor)

*我有另一张表tbl_students,其中包含所有学生的记录(id,

fName,lName,rollNo,Class ....等)。

*我想显示的记录所有的学生班都很聪明。



一级0楼$

----------------

student1

student2

student3

student4



二级楼0

----------------

student5

student6

student7

student8













请建议一些解决方案。



谢谢,



问候,

Ashish

Hi,

I want a replacement of nested repeater in MVC 4.0.
Actually, My scenario is something like:

* I have a table "tbl_class" which contains contains records of all the classes(id, class, floor)
* I have another table "tbl_students" which contains records of all the student(id,
fName,lName,rollNo,Class....etc).
* I want to show records of all the student class wise.

Class I floor 0
----------------
student1
student2
student3
student4

Class II floor 0
----------------
student5
student6
student7
student8
.
.
.
.
.

Please suggest some solution.

Thank you,

Regards,
Ashish

推荐答案

1.ASP.NET MVC与ASP.NET不同,它有内置的控件,你也可以在设计模式下看到。



2.在MVC中你应该按顺序使用 razor代码和HTML元素(比如 div )建立你的观点。



3.从控制器你应该通过模型查看,以及必须包含要显示的数据的模型 。然后在视图中,您应该使用 @foreach (razor视图块代码)动态构建每个元素的每个HTML控件组。



4.在你的情况下,Model应该使用剃刀代码,如下例所示:

1.ASP.NET MVC is different then ASP.NET where there are built in controls that you can see also in design mode.

2.In MVC you should use razor code and HTML elements (like div) in order to build your views.

3.From the Controller you should pass the Model to the View, and the Model that must contains the data that you want to display. Then in the view you should use @foreach (razor view block of code) to built dynamically each HTML groups of controls for each element.

4.In your case the Model should use razor code like in the next example:
public class StudentClassInfo
{
public string ClassName{get; set;}
public int ClassFloor{get;set;}
private List<StrudentInfo> _students= new List<StrudentInfo>();
public List<StrudentInfo> Students{ get {return _students;}}
//....

}

public class StudentInfo
{
public string Name{get;set;}
//...
}



5.在您的视图中,您应该使用您的模型数据,如下一个示例所示:


5.In your view you should use your model data like in the next example:

@model List<StudentClassInfo>
<div>
@foreach (StudentClassInfo item in Model) {
     <div>Class @item.ClassName @item.ClassFloor<br/>
     <hr/>
     @foreach(StudentInfo studentInfo in item.Students)
     {
         @studentInfo.Name
         <br/>   
     }
     <br/>
     </div> 
}
</div>


这篇关于在MVC 4.0中替换嵌套的转发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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