Problem
I want to display a form that will have a variable amount of values. However each form item has to have a sort of key associated with it. For example, the form generates a name, username and occupation fields, I need to also have keys generated so when the form is submitted, the receiver method can tell what items are what.
Attempted Solution
Right now I have a list of FieldItems where a FieldItem is just a class with one class variable of a String. The solution works when populating the form, however on submission a list is returned and I can not tell which value belongs to which key. I was thinking about using a dictionary but I do not know how this would be accomplished in razor.
View Model
public class BuildReportViewModel
{
public IList<BuildReportFieldItemViewModel> Fields { get; set; }
}
public class BuildReportFieldItemViewModel
{
public string Field { get; set; }
}
Editor for BuildReportFieldItemViewModel
@model BuildReportFieldItemViewModel
<div class="editor-label">
<label for="@Model.Field">@Model.Field</label>
</div>
<div class="editor-field">
<input type="text" name="@Model.Field">
</div>