To Long to Read (tl;dr):
Make this add a new cell to a table that shows a razor/mvc dropdown:
var element1 = document.createElement(@Html.DropDownListFor(m => m.Contact.Attribute, Model.Contact.Attributes, new { @class = "form-control" }));
Long but more detailed question:
Pretty simple answer, I think, but I'm just too new to Razor to know.
Currently, I have a table that has rows added using JavaScript by means of a 'add row' button.
I actually asked the question before, and found a solution that worked perfectly. However, now I need it in Razor so my previous question can't work.
Here's the link with pictures to my other post:
Create Dynamic Elements that are MVC Format
Ok so new issue. I have a razor element that needs to be duplicated with JavaScript. I've changed the names of the classes and properties.
So in the table, I have:
<td>@Html.DropDownListFor(m => m.Contact.Attribute, Model.Contact.Attributes, new { @class = "form-control" })</td>
Which works great. The table populates with this in it just fine. However, like in my other post, I need to replicate the entire line with JavaScript (or whatever other solution there is).
Currently, I have this style of insert:
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name = "[#].chkbox";
element1.className = "form-control";
cell1.appendChild(element1);
The type changes from text to email to tel. The '#' in name = "[#].chkbox" actually is a variable that is passed through, so each of the # are different. Somehow, someway, I want to do:
var element1 = document.createElement(@Html.DropDownListFor(m => m.Contact.Attribute, Model.Contact.Attributes, new { @class = "form-control" }));
Note: the rendered version keeps turning out like this
var element2 = document.createElement(<select class="form-control" id="InjuredPerson_SuspectedInjury" name="InjuredPerson.SuspectedInjury"><option value="A.G.E.">A.G.E.</option>