ASP.NET MVC - 如何传递一个Array的看法? [英] ASP.NET MVC - How to pass an Array to the view?
问题描述
我在这里挣扎自己,找到一个简单的方法来从控制器的阵列传递到ASP.NET MVC框架的看法。
I'm struggling myself here, to find a easy way to pass an array from the controller to the view on ASP.NET MVC framework.
所以在我的控制器我会是这样的:
so in my controller I would have something like:
public class HomeController : ApplicationController
{
public ActionResult Index()
{
string[] myArray = { "value01", "value02", "value03"};
ViewData["passedArray"] = myArray;
return View();
}
}
所以我认为我会只是一个的ViewData调用[passedArray] ,并在其上运行的循环。
so in my view I would have just a call to ViewData["passedArray"] and run a loop on it.
但显然在的ViewData B>正在被查看收到的 System.String ,可能是因为对数组类型的报关,但不幸的是,我不知道该怎么通过它正确,只是没有创造数百万code线。
But apparently the ViewData is being received by the view as System.String, probably because of the declaration on the Array DataType, but unfortunately I don't know how to pass it properly and simply without create millions of code lines.
这将是美妙的,如果人能帮助我。
It would be fantastic if one could help me.
在此先感谢
推荐答案
您需要在浏览投
<% var myArray = (string[])ViewData["passedArray"]; %>
这篇关于ASP.NET MVC - 如何传递一个Array的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!