MVC3 homecontroller의 Index 메서드에 다음 코드가 있습니다. 내가 시도하고있는 것은 내 리소스 파일 (.resx)에서 값을 가져 와서보기에 표시하는 것입니다.null 참조 MVC3
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>
}
어떻게 해결할 수 있습니까?
NullReferenceException이가에 목록을 만드시겠습니까? – jrummell
text.myList.Add (x); – Aqua
은 text.myList가 제대로 초기화 되었습니까? – msancho