When the user clicks a button, the following HTML gets added to the page by Javascript, and the value of IncrNumber increases each time the button is clicked, so the first click would produce divs with the following ID's: (start0, end0, comm0) and the second click would produce ID's (start1, end1, comm1) and so on.
Start: <input type="text" class="form-control" id="start' + IncrNumber + '"/>
End: <input type="text" class="form-control" id="end' + IncrNumber + '" />
Comment: <textarea rows="4" class="form-control" id="comm' + IncrNumber + '"></textarea>
Since these divs are being dynamically added with Javascript, I cannot use Razor and therefore cannot convert these text boxes into "HTML.TextBoxFor(x.start)..."
Since clicking a button will generate a variable, unlimited number of these fields, I cannot add them to my Model, anyways.
How can I get the values of startX, endX, and commX in my controller?
EDIT:
There exists a Many-To-One relationship between DBO.Televiewers[ID, Date] and DBO.Annotations[ID, TeleviewerID, Start, End, Comment]. The user can add as many Annotation objects as they want per Televiewer.
VIEW:
<div class="panel panel-form-5">
<div class="panel-heading">
<h3 class="panel-title">Edit Televiewer</h3>
</div>
<div class="panel-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.Label("Hole Name")
@Html.EditorFor(m => m.HoleName, new { htmlAttributes = new { @class = "form-control" } })
<br />
@Html.Label("Televiewer Date")
@Html.EditorFor(m => m.TeleviewerDate, new { htmlAttributes = new { @class = "form-control" } })
<br />
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-lg-10">
<h4>Annotations</h4>
</div>
<div class="col-lg-2">
<div id="addbuttondiv">
<button onclick="addAnswer(); return false;" class="btn btn-default">Add New</button>
</div>
</div>
</div>
<hr />
<div id="annotations">
</div>
</div>
</div>
<br />
@Html.ActionLink("Back", "Index", "Televiewer", null, new { @class = "btn btn-default" })
<input type="submit" value="Calculate & Save" class="btn btn-primary" />
}
</div>
</div>
<script>
var answers = 0;
function addAnswer() {
var write = document.getElementById('annotations');
write.innerHTML += ' <div class="row"><div class="col-lg-3 col-lg-offset-1">Start Depth: <input type="text" class="form-control" id="start' + answers + '"/></div><div class="col-lg-3 col-lg-offset-4" >End Depth: <input type="text" class="form-control" id="end' + answers + '" /></div></div><br /><div class="row"><div class="col-lg-1 col-lg-offset-2"><br />Comment:</div><div class="col-lg-6"><textarea rows="4" class="form-control" id="comm' + answers + '"></textarea></div></div><hr/>';
answers++;
}
</script>