如何使用ViewBag存储字符串数组
我想将一组字符串存储到控制器中的 ViewBag 中,以便在我的视图中使用。我希望能够做到这一点:
ViewBag.Autobots[0].FirstName = "Bumble"
ViewBag.Autobots[0].LastName = "Bee"
ViewBag.Autobots[1].FirstName = "Optimus"
ViewBag.Autobots[1].LastName = "Prime"
但是,为了做到这一点,我需要首先声明 Autobots 数组。我尝试了几种不同的方法,但被这个看似简单的事情绊倒了。希望得到一些帮助!
I want to store a set of strings into the ViewBag in my Controller for use in my view. I want to be able to do this:
ViewBag.Autobots[0].FirstName = "Bumble"
ViewBag.Autobots[0].LastName = "Bee"
ViewBag.Autobots[1].FirstName = "Optimus"
ViewBag.Autobots[1].LastName = "Prime"
However, in order to do this I need to first declare the Autobots array. I've tried a few different ways, but getting tripped up on this seemingly simple thing. Would love some help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
然后根据您的代码,您可以开始为其赋值:
then as per your code you can start to assign values to it: