简体   繁体   English

从控制器到视图传递许多变量/参数

[英]Passing many variables/parameters from Controller to View

How do i pass many parameters to View from Controller? 如何将许多参数从Controller传递到View?

I need to, depending on controller, show pictures on website. 我需要根据控制器在网站上显示图片。 I am trying to pass their adresses to View but I don't think it is effective. 我正在尝试将其地址传递给View,但我认为这无效。

In addition i don't know if there will be 5 of them or 5 blocks of 50, I do have to have also some kind of counter. 另外我不知道是否会有5个或5个50块,我也必须有某种计数器。

The ideal solution would be, if I can pass whole object to View but I don't know if it is possible and if it is, how to do this. 理想的解决方案是,如果我可以将整个对象传递给View,但不知道是否可行,以及如何做到这一点。

You will need to create an ViewModel and then in the controller pass for example a List of Images to the view. 您将需要创建一个ViewModel,然后在控制器中将例如图像列表传递给视图。

I am not sure how do you store the images because you do not refer that in your question but you can for example store them in the file system and then in the controller just make a list of paths to those images. 我不确定如何存储图像,因为您没有在问题中提及该图像,但是可以例如将其存储在文件系统中,然后在控制器中仅列出这些图像的路径。

Alternatively you can store the images in the database and then in the controler get them from the database and add them to the ViewModel. 或者,您可以将图像存储在数据库中,然后在控件中从数据库中获取它们并将它们添加到ViewModel中。

If you need more help just let me know. 如果您需要更多帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM