Let's say you have this model:
//model public class Stuff { public string Name { get; set; } public Dictionary<String, String> Description { get; set; } }
I want to be able to create an action and an appropriate view so that users can add an Object Name object to the form and add several descriptive entries.
In this particular case, I want the key to be a language code of the type "en", "de", "fr", "es", etc., and the description should be the corresponding description for this language.
For example, in the view, you can see something like this:
@model Stuff @using(Html.BeginForm()) { <div> @Html.LabelFor(x=>x.Name) @Html.TextBoxFor(x=>x.Name) </div> <div> <input name="LanguageCode" value="en" /> <input name="DescriptionValue" /> <input name="LanguageCode" value="de" /> <input name="DescriptionValue" /> <input name="LanguageCode" value="fr" /> <input name="DescriptionValue" /> </div> <div> <input type="submit" value="save" /> </div> } // controller [HttpGet] public ActionResult Index () { return View(new Stuff()); } [HttpPost] public ActionResult Index (Stuff myStuff) { foreach(KeyValuePair kvp in myStuff.Description) { Trace.WriteLine(String.Format("Language: {0} - Description: {1}", kvp.Key, kvp.Value)); } DBHelper.Save(myStuff); return View(); }
Any alternative decisions are made.
Thanks.
agarcian
source share