MVC 3 - 如何显示在一个视图索引视图,而不是一个ID字段的查找值 [英] MVC 3 - How to display a lookup Value in a view Index view instead of an ID field
本文介绍了MVC 3 - 如何显示在一个视图索引视图,而不是一个ID字段的查找值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个pretty的简单的需求,但我无法弄清楚它是如何能够做到
I have a pretty simple need but am unable to figure how it could be done
我有2个实体
- 员工
- 商店
这是员工与商店,如有关(DB)
An employee is associated with a store such as (DB)
Employee_id, Store_id
1 1
2 1
而在索引视图我需要显示 Store_nam
电子商务不是 STOREID
。这是做它的理想MVC的方式?我使用LINQ to SQL作为数据访问方法。
While in the Index View I need to show the Store_nam
e instead of the StoreID
. Which is ideal 'MVC' way of doing it? I am using LINQ to SQL as the data access method.
推荐答案
我假设你的模型的类型是的IEnumerable<员工>
,你都出现在一个表通过foreach循环产生的。
I assume that your model is of type IEnumerable<Employee>
and you are showing it in a table generated by a foreach loop.
那么你应该能够做到这一点:
Then you should be able to do this:
@foreach(var item in Model){
Html.DisplayFor(modelItem => modelItem.Store.Store_name)
}
这篇关于MVC 3 - 如何显示在一个视图索引视图,而不是一个ID字段的查找值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文