Asp.net mvc 3 使用Editortemplates在mvc3中动态添加控件
在我的程序中,我试图在点击按钮时动态添加额外的控件。是否可以使用EditorTemplates? 这是我的编辑模板Asp.net mvc 3 使用Editortemplates在mvc3中动态添加控件,asp.net-mvc-3,razor,Asp.net Mvc 3,Razor,在我的程序中,我试图在点击按钮时动态添加额外的控件。是否可以使用EditorTemplates? 这是我的编辑模板 @model chPayroll.Models.HREducation.HRInfo @{ var list = (IEnumerable<SelectListItem>)TempData["PassedDivision"]; var list1 = (IEnumerable<SelectListItem>
@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>
@model chPayroll.Models.HREducation.HRInfo
@{
变量列表=(IEnumerable)TempData[“PassedDivision”];
var list1=(IEnumerable)TempData[“国家”];
}
@Html.HiddenFor(x=>x.StaffId)
@Html.DropDownListFor(x=>x.Country,列表1,“-select-”)
@Html.TextBoxFor(x=>x.Board)
@Html.TextBoxFor(x=>x.Level)
@Html.TextBoxFor(x=>x.PassedYr)
@DropDownListFor(x=>x.PassedDivision,list,“-selected-”)
现在我想在单击按钮时动态添加所有控件。
我正在从视图中调用listeditor
@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
@model chPayroll.Models.HREducation.HRInfo
@使用(Html.BeginForm(“Addcontrols”,“HREduInformation”,FormMethod.Post))
{
国家
董事会
水平仪
过去的一年
分部
证明书
@EditorFor(m=>m.listInfoeditor)
}
您可以使用Ajax获取呈现的控件Html
您还可以更进一步,通过在客户端使用已经呈现的模板来避免ajax调用