Using Razor code, how can I bind a list of Widgets to the List<WidgetModel>
in my Model? I assume there's an easy standard way to do this as it seems like a common scenario.
I have a model with a list of widgets, like this:
public class CustomerModel
{
public List<WidgetsModel> widgets { get; set; }
}
I also have a View where the user can add widgets
<input type="button" id="add-link" value="Add"/>
<div class="widget-wrapper">
<p>Widget Name:</p>
@Html.TextBoxFor(m => m.widgets.name)
<p>Widget Price:</p>
@Html.TextBoxFor(m => m.widgets.price)
<hr>
</div>
<script type="text/javascript">
$('#add-link').on('click', function(){
var x = $('.widget-wrapper')[0].outerHTML;
$(x).insertAfter(this);
});
</script>