网上找到不少资料,其实很简单
后台控制器:
public ActionResult GetExamStuListHtml(string ExamMouldId)
{
//生成前台HTML控件
StringBuilder sb = new StringBuilder();
t_QuestionApp QuestionApp1 = new t_QuestionApp();
DataSet ds = QuestionApp1.p_ExamStu_Add(ExamMouldId);
for (int index=0;index< ds.Tables[0].Rows.Count;index++)
{
sb.Append(@"<input id='Checkbox_'"+index+" type='checkbox' />");
}
return Success("成功", sb.ToString());
}
前台根据选择的模板,生成不同的HTML:
<tr>
<th class="formTitle">模板选择</th>
<td class="formValue">
<select id="F_ExamMouldId" name="F_ExamMouldId" οnchange="GetExamQuestion();" class="form-control required">
</select>
</td>
</tr>
用于显示HTML标签的DIV
<div class="panel-body" style="width: 98%;">
<div id="examquestion"></div>
</div>
JS脚本:
function GetExamQuestion() {
$.ajax({
url: "/SAE/Question/GetExamStuListHtml",
data: { ExamMouldId: $("#F_ExamMouldId").val() },
type: "post",
dataType: "json",
success: function (data) {
$('#examquestion').html(data.data);
}
});
}