I have some form in which I want to automatically generate new textbox on + button click and then I want to submit it to CandidateRegister action method in Candidates controller.
@model SourceTreeITMatchmaking.Models.CandidateRegisterViewModel
Candidates View
@using (Html.BeginForm("CandidateRegister", "Candidates"))
{
<div id="myTechnologies">
<div class="row">
<div class="col-sm-6" style="padding-left: 0;">
@Html.TextBoxFor(m => m.SelectedMyTechnologies.Technology, new {@class="form-control", placeholder="C#, Java, Sql Server..."})
</div>
</div>
</div>
<hr class="mt60">
<div class="clearfix">
<input type="submit" class="btn btn-default btn-large pull-right" value="Register candidate!">
</div>
}
jQuery function to add new Textbox on (+) button click
$("#add-technology-candidate").click(function () {
var firstDiv = $(' <div class="row"> <div class="col-sm-6" style="padding-left: 0;"> ' +
' <input type="text" class="form-control" placeholder="C#, Java, Sql Server..." /> </div>');
$("#myTechnologies").append(firstDiv.append(deleteButton));
});
One propery of my CandidateRegisterViewModel which I use for strongly typed model
public class CandidateRegisterViewModel
{
public SelectedMyTechnologies SelectedMyTechnologies { get; set; }
}
/Property that I use in CandidateRegisterViewModel/
public class SelectedMyTechnologies
{
public List<string> Technology { get; set; }
}
Long story short-> I want to generate textbox on (#add-technology-candidate) button click and then pass user entered data as a list to my controller. As my code is right now, I can only pass data from first textbox (not dynamically generated one). How should I change jQuery method to support both types?
Thanks in advance.