如何在MVC中访问Collection中的对象 [英] How to access objects in a Collection in MVC
本文介绍了如何在MVC中访问Collection中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
在我的项目中,我有一个actionResult方法返回这样的对象集合:
public ActionResult PartNumberManufacturer( string id)
{
var partNumber = Context.PartNumberTable.Where(x = > x.PartNumberId == id);
return PartialView( PartNumberView,partNumber);
}
如何迭代我的集合abd访问集合中的每个对象?
对不起我对MVC有些新意..
谢谢
解决方案
@ foreach(var part)在模型中)
{
< p > @ part.SomeProperty < / p >
}
获取一本关于MVC的书或至少通过一些在线教程。论坛不是从头学习东西的最佳场所。
为了更多的理解,你可以在下面查看网址:
http://www.c-sharpcorner.com/UploadFile/deveshomar/simple-way-of-binding-list-of-objects-to-view-using-mvc/
Hi All,
In my project I have got an actionResult method returning a collection of objects like this:
public ActionResult PartNumberManufacturer(string id)
{
var partNumber = Context.PartNumberTable.Where(x => x.PartNumberId == id);
return PartialView("PartNumberView", partNumber);
}
How would I iterate my collection abd access each object in the collection??
Sorry I am slighty new to MVC..
Thank you
解决方案
@foreach(var part in Model) { <p>@part.SomeProperty</p> }
Get a book on MVC or at least go through some tutorials online. A forum is not the best place to learn something from scratch.
For more understanding,you can view below url:
http://www.c-sharpcorner.com/UploadFile/deveshomar/simple-way-of-binding-list-of-objects-to-view-using-mvc/
这篇关于如何在MVC中访问Collection中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文