I have a template
<script id="template" type="text/x-jquery-tmpl">
<div class="experience">
<label for="c${count}">New Thing:</label>
<input type="text" id="c${count}" name="Fund[${count}].Name" />
<label for="c${count}">New Thing count:</label>
<input type="text" id="c${count}" name="Fund[${count}].FundNo" />
</div>
to which I add controls dynamically to a div container.
I have a model in my mvc application
[Serializable]
public class Step2ViewModel : IStepViewModel
{
[Required]
public List<FormTest.Models.Item> Things;
}
[Serializable]
public class Item
{
public string Name { get; set; }
public string Number { get; set; }
}
How do I bind these newly created controls to a model. Does that entail using
@Html.LabelFor, @Html.TextBoxFor etc in my template?
thanks!
Edit:
Just in case the question is open to interpretation – I want to bind dynamically created controls ( which was done using templ() ) to the List in my model when the form is posted.
First of all, you are using a project that will no longer have more updates and it was never finished.
Boris Moore created a way to continue jQuery template project and it’s called JsRender. With JsRender you have the power of jQuery Templates, and much much more, like accessing paths, use of helper functions, have no dependency on jQuery whatsoever, and list goes on and on…
PluralSight have an entire 3 hours course just for JsRender (so you can see the importance of it), you can start seeing it with a Trial account.
Now regarding your actual issue
Every time you want to make the .NET framework fill up the Model for you upon submitting a form, you have to make sure that you write the each property as you had an array, so you need to pass the entire full path of your model.