Im trying to get the value based on key from a dictionary with the following statement:
It just throws NULL reference exception, but I do have a Key value pair with the key "MyKey"
@Model.DictionaryTest["MyKey"]
Should I be using a List of Dictionaries? If so can you give me the statement to retrieve from that?
UPDATE-- This is the class I'm passing as Model and in the controller I'm populating the dictionary.(I've checked the values are intact)
public class Dummy_PreHires_View_Model
{
public Dictionary<string, string> DictionaryTest { get; set; }
}
This is one of the data on the dictionary, if this helps, i've tried with the key mentioned on the picture, still throws NULL exception: Dictionary data snap
MY Controller Code:
public ActionResult PreHires_Dummy()
{
ViewBag.PreHires_Dummy_class = "active";
Dummy_PreHires_View_Model dpvm = new Dummy_PreHires_View_Model();
Dummy_PreHires_Translate_Model dptm = new Dummy_PreHires_Translate_Model();
dpvm.DictionaryTest = dptm.GetTranslatedData();
return View(dpvm);
}
I wrote a sample here. I hope it will help you.
Model:
Controller:
View: