I have created a special User Control which inherits KeyValuePair. Inside my ViewModel, there is a property called lookup
[UIHint(\"Lookup\")]
public KeyValuePai
The KeyValuePair
structure doesn't have a default parameterless constructor and can't be instantiated by the model binder. I recommend a custom model class for your view that has just those properties.
public class CustomControlViewModel
{
public string Key { get; set; }
public string Value { get; set; }
}
Transform your KVP into this model class for your view and/or use this class as the parameter on your action.
[HttpGet]
public ActionResult Lookup()
{
return View( new CustomControlViewModel { Value = kvp.Value, Key = kvp.Key } );
}
[HttpPost]
public ActionResult Lookup( CustomControlViewModel lookup )
{
...
}