我在我的MVC3主控制器的索引方法中有以下代码。我正在尝试的是,从我的资源文件(.resx)中获取值,并将它们显示在视图中。
private ResourceManager rm = null;
private ResourcesTexts text;
public ActionResult Index()
{
text = new ResourcesTexts();
rm = new ResourceManager("Credit.SiteResources", Assembly.GetExecutingAssembly());
var res = rm.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry resource in res)
{
if (resource.Key.ToString().Count() == 14)
{
string x = resource.Value.ToString();
text.myList.Add(x);
}
}
return View(text);
}我在调试时遇到空引用错误。
有什么帮助吗?
在我看来,我正在尝试这样的东西。
@foreach(var x in Model.myList.Item)
{
<p>@x</p>
}我该怎么解决呢?
发布于 2012-10-30 21:33:40
试试这个:
text = new ResourcesTexts();
text.myList = new List<string>();或
在ResourcesTexts构造函数中创建列表
https://stackoverflow.com/questions/13139881
复制相似问题