I have a template builder that creates section and question sets from a template and then saves to a DB. I am having problems explicitly linking the view to the model as the section and question numbers are dynamic and there are no set amounts:
<div class="form-group">
@Html.LabelFor(model => model.S{{section}}Name, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.S{{section}}Name)
@Html.ValidationMessageFor(model => model.S{{section}}Name)
</div>
</div>
Without the use of the template the above would look like this:
<div class="form-group">
@Html.LabelFor(model => model.S1Name, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.S1Name)
@Html.ValidationMessageFor(model => model.S1Name)
</div>
</div>
I am trying to dynamically assign these using the templates required method
{{}}
This is not liked by MVC when used like this. I have had no other problems inserting data anywhere else on the same page. Is there a way around this?
Any ideas or help would be appreciated.
You can't design the template the way you want using the expressions. I'd recommend using the array approach that MVC more inherently uses for something like this, where each item is an array in the model, rather than having the number in the model property name.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments