在剃刀视图中创建一个全局列表 [英] making a list global in razor view

查看:91
本文介绍了在剃刀视图中创建一个全局列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在控制器中创建一个列表并在其中添加内容。现在我想将它传递给任何视图。所以我需要让它全球化。我该怎么做。我能得到这个语法吗。



谢谢你

I''m creating a list in a controller and adding stuff in it. Now i want to pass it to any of the views. So I need to make it global i guess. how can I do it. can i get the syntax please.

Thank you

推荐答案

1.First解决方案:你可以简单将其缓存到控制器中的 ViewBag 中,然后在视图中使用它。



2.您可以添加列表作为模型中的属性;只需扩展您的模型并添加一个列表类型的属性。
1.First Solution: You can simple cache it into the ViewBag in the controller, then use it in the Views.

2.You can add the list as property in your model; just extend your model and add it a property of type your list.


这篇关于在剃刀视图中创建一个全局列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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