I need to allow my user to fill out a form and then click an 'Add' button. Then, a row in a table is populated with their input values. They also have the option to click an 'x' to remove the row if they change their mind.
Here is what it looks like:
This all works, but I have no idea how to represent the form values in the model. Can I make something like a struct of the values and then just add them into an array? How would I do that?
Also, here is my code: (I'm populating these DropDownLists in typescript and adding a listener to add the selected value to the hiddenfor element which is the actual element hooked up to the model)
<div class="col-sm-6">
<div class="field col-sm-12">
@Html.HiddenFor(x => x..CallType, new { id = "CallType-List_Value" })
@Html.DropDownList("CallType", new SelectList(" "), new { @class = "CallType-List form-control" })
@Html.ValidationMessageFor(x => x.CallType, "", new { @class = "text-danger" })
@Html.LabelFor(x => x.CallType)
</div>
<div class="field col-sm-12">
@Html.HiddenFor(x => x.CallSubType, new { id = "CallSubType-List_Value" })
@Html.DropDownList("CallSubType", new SelectList(" "), new { @class = "CallSubType-List form-control" })
@Html.ValidationMessageFor(x => x.CallSubType, "", new { @class = "text-danger" })
@Html.LabelFor(x => x.CallSubType)
</div>
<div class="field col-sm-12">
<div class="field">
@Html.EditorFor(x => x.AccountNumber, new { htmlAttributes = new { placeholder = " " } })
@Html.LabelFor(x => x.AccountNumber)
@Html.ValidationMessageFor(x => x.AccountNumber, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="small-btn col-sm-12" style="border-top: none !important;">
<button type="button" class="btn btn-primary">ADD INCIDENT</button>
</div>
And the model so far:
public string CallType { get; set; }
public string CallSubType { get; set; }
[RegularExpression(@"^[0-9]*$", ErrorMessage = "Account number is not valid.")]
[StringLength(16, ErrorMessage = "Account number cannot be longer than 15 characters.")]
public int AccountNumber { get; set; }
I'm super new to .NET, so please forgive me if the answer is obvious.
