In my program I am trying to add extra controls dynamically on button click.Is it possible by using EditorTemplates?
This is my EditorTemplates
@model chPayroll.Models.HREducation.HRInfo
@{
var list = (IEnumerable<SelectListItem>)TempData["PassedDivision"];
var list1 = (IEnumerable<SelectListItem>)TempData["Country"];
}
@Html.HiddenFor(x => x.StaffId)
<tr>
<td>@Html.DropDownListFor(x => x.Country, list1, "-select-")</td>
<td>@Html.TextBoxFor(x=>x.Board)</td>
<td>@Html.TextBoxFor(x=>x.Level)</td>
<td>@Html.TextBoxFor(x=>x.PassedYr)</td>
<td>@Html.DropDownListFor(x=>x.PassedDivision,list,"-selected-")</td>
<td><input type="file" name="file"></td>
</tr>
Now I want to add all controls dynamically on button click.
I am calling listeditor from the view.
@model chPayroll.Models.HREducation.HRInfo
<div align="left">
<fieldset style="left:0px">
@using (Html.BeginForm("Addcontrols", "HREduInformation", FormMethod.Post))
{
<table >
<tr>
<th >Country</th>
<th>Board</th>
<th>Level</th>
<th>Passed Year</th>
<th>Division</th>
<th>certificate</th>
</tr>
@Html.EditorFor(m => m.listInfoeditor)
</table>
<input type="submit" value="Add New" id="savechanges" />
}
</fieldset>
</div
You can use Ajax to grab the rendered control Html.
Editing a variable length list
You can also go one step further and avoid the ajax call by using an already rendered template on the client side