在MVC 4中使用数据库中的数据填充单选按钮,而不使用模型
fill radiobutton with data from data base in mvc 4 without using model
控制器中的代码:此操作从数据库中获取数据并使用此数据填充(classlist)
public ActionResult GetClassListForTeacher()
{
List<string> classlist = null;
ProfileEntities pe= new ProfileEntities();
string uID = HttpContext.Session["NID"].ToString();
int year = 2011;
//int year = DateTime.Now.Year;
int session = set_session();
if (session == 1)//teacher
{
classlist = (from c in pe.CLASSES
join lc in pe.LESSON_CARDS
on new { EDUSTG_CODE = c.EDUSTG_CODE, STATISTICAL_CODE = c.STATISTICAL_CODE, FIRST_YEAR = c.FIRST_YEAR,
GRD_CODE = c.GRD_CODE , OCF_CODE = c.OCF_CODE , CLS_SN = c.CLS_SN}
equals new { EDUSTG_CODE = lc.EDUSTG_CODE, STATISTICAL_CODE = lc.STATISTICAL_CODE_BELONGS_TO, FIRST_YEAR = lc.FIRST_YEAR,
GRD_CODE = lc.GRD_CODE , OCF_CODE = lc.OCF_CODE_BELONGS_TO , CLS_SN = lc.CLS_SN}
where (lc.NID == uID && lc.FIRST_YEAR_HAVE == year)
select c.NAME
).ToList();
}
if (session == 2)//student
{}
return Json(classlist, JsonRequestBehavior.AllowGet);
}
view
中的代码<div class="dialog-fluid" id="MoreOptionModal" style="display: none; height: 300px; overflow: scroll;" title="Options">
<div class="row-fluid">
<div class="block-fluid">
<div class="row-form">
<div class="span12">
<table style="border: 0;">
<tr>
<td style="border: 0;">@Html.RadioButton("type","Friendes",false,new { id = "Friendes"})</td>
<td style="border: 0;"><label>All Friendes</label></td>
</tr>
<tr>
<td style="border: 0;">@Html.RadioButton("type","Teachers",false,new { id = "Teachers"})</td>
<td style="border: 0;"><label>All Teachers As Friends</label></td>
</tr>
<tr>
<td style="border: 0;"></td>
<td style="border: 0;">@Html.RadioButton("type","Same School",false,new { id = "Same_School" })</td>
<td style="border: 0;"><label>Same School</label></td>
</tr>
<tr>
<td style="border: 0;"></td>
<td style="border: 0;">@Html.RadioButton("type","Other School",false,new { id = "Other_Schools"})</td>
<td style="border: 0;"><label>Other School</label></td>
</tr>
<tr>
<td style="border: 0;">@Html.RadioButton("type","Schoolmates",false,new { id = "Schoolmates"})</td>
<td style="border: 0;"><label>All Students As Friends</label></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
我想在最后一个单选按钮(同学)之后添加单选按钮列表这是js
中的代码 $("#MoreOptionModal").dialog({
autoOpen: false,
modal: true,
});
$("#options").live("click", function () {
debugger;
$("#MoreOptionModal").dialog('open');
$.ajax({
url: "/Mail/GetClassListForTeacher",
type: "POST",
datatype: "json",
data: { },
traditional: true,
success: function (result) {
}
});
});
问题是我的视图中已经有了模型我从数据库中检索数据我想显示我的视图
将此代码添加到success函数中,当然您必须根据您的需求调整解决方案,但基本上这是一个变通方法。
$.each(result, function(i, name){
var trToAppend="
<tr>
<td style="border: 0;"><input type='radio' name='type' id='" + name + "'/></td>
<td style="border: 0;"><label>" + name + "</label></td>
</tr>
";
$('table').append(trToAppend);
});
js代码
$("#options").live("click", function () {
debugger;
$("#MoreOptionModal").dialog('open');
$.ajax({
url: "/Mail/GetClassListForTeacher",
type: "POST",
datatype: "json",
data: { },
traditional: true,
success: function (result) {
$("#ForTest").val(result);
var d = $("#ForTest").val().split(",");
for (var i = 0; i < d.length; i++) {
//alert(d[i])
var trToAppend="<tr><td><input type='radio' name='type' id='" + d[i] + "'/></td><td><label>" + d[i] + "</label></td></tr>";
$("#MyTest").append(trToAppend);
}
}
});
});
我在view
中添加了这一行<input id="ForTest" type="hidden" />
我将列表拆分然后添加HTML
相关文章:
- 多个单选按钮组相互干扰
- Angularjs无法将单选按钮与嵌套范围内的模型绑定
- 使用带角度的单选按钮更新不同的模型
- 使用嵌套ng中带有单选按钮的ng模型重复不起作用
- 构建淘汰模型并动态查看,不设置单选按钮
- NG-模型似乎只在模态视图内的离子单选按钮上绑定一种方式
- 单选按钮中的 ng 模型始终未定义
- 表单提交不会更新绑定到单选按钮的模型
- 使用角度模型单击按钮后,将值设置为单选按钮
- 未从视图模型(KNOCKOUTJS)设置单选按钮
- 角度材质单选按钮模型未更新
- 在MVC 4中使用数据库中的数据填充单选按钮,而不使用模型
- 当ng模型更改时,形成引用旧内存的单选按钮-中断ng检查
- Angularjs:当模型改变时,单选按钮检查状态绑定模型值失败
- Angularjs:当单选按钮选择改变时更新模型
- 将相同的模型变量绑定到单选按钮和输入文本
- 内有角度单选按钮模型ng重复
- AngularJS:如何在模型改变时改变单选按钮视图
- AngularJS-将单选按钮选择绑定到模型内部ng重复
- AngularJS-单选按钮不更新模型