Я занимаюсь разработкой системы посещаемости студентов в asp. net. Я сталкиваюсь с проблемой, когда я передаю несколько значений раскрывающегося списка в контроллер. Я использовал один и тот же раскрывающийся список несколько раз, поэтому помогите мне, как я могу отправить несколько значений раскрывающегося списка в контроллер. Это мой контроллер.
public ActionResult TakeAttendence(FormCollection c)
{ ViewData["c_id"] = new SelectList(db.ClassTbs, "c_id", "Class_Name");
int cid=Int32.Parse(Request.Form["c_id"].ToString());
//this viewdata is used for display status on view
ViewData["a_id"] = new SelectList(db.AttendenceValues, "a_id", "Status");
List<StudentTb> stu = db.StudentTbs.ToList();
List<ClassTb> cls = db.ClassTbs.ToList();
List<Attendence> att = db.Attendences.ToList();
var res = from s in stu
where s.c_id == cid
join cl in cls on s.c_id equals cl.c_id into table1
from cl in table1.DefaultIfEmpty()
join a in att on s.s_id equals a.studentId into table2
from a in table2.DefaultIfEmpty()
select new GeneralClass { studenttb = s, classtb = cl , attendencetb = a };
List<GeneralClass> g = res.ToList();
foreach(var cd in g)
{
cd.studenttb.s_Date = DateTime.Now;
// cd.attvalue = db.AttendenceValues.ToList();
// cd.studenttb.attval = db.AttendenceValues.ToList();
}
return View(g);
// return View(res);
}
//this is post method
[HttpPost]
public ActionResult SubmitAttndence(List<GeneralClass> model )
{
foreach (var i in model)
{
var userRows = db.Attendences.Where(x =>
x.StudentTb.s_id.Equals(i.studenttb.s_id)).SingleOrDefault();
if (userRows == null)
{
Attendence userRow = new Attendence();
userRow.Date = i.studenttb.s_Date;
userRow.Status=Int32.Parse(Request.Form["a_id"].ToString());//here
//I received dropdown list values it work fine when I take only
//one
//student attendance but when students are two or more it show
//null
//values
userRow.Remarks = i.studenttb.s_remarks;
userRow.studentId = i.studenttb.s_id;
db.Attendences.Add(userRow);
db.SaveChanges();
}}
return view();}
А это мой вид
@using (@Html.BeginForm("SubmitAttndence", "Student", FormMethod.Post))
{
<table>
<tr>
<th>s_id</th>
<th>first Name</th>
<th>Last Name</th>
<th>Date</th>
<th>Remarks</th>
<th>Status</th>
</tr>
@if (Model != null)
{
for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
@Html.HiddenFor(model => model[i].studenttb.s_id)
</td>
<td>
@Html.EditorFor(model => model[i].studenttb.F_Name, new {
htmlAttributes = new { @readonly = "readonly" } })
</td>
<td>
@Html.EditorFor(model => model[i].studenttb.L_Name, new {
htmlAttributes = new { @readonly = "readonly" } })
</td>
<td>
@Html.EditorFor(model => model[i].studenttb.s_Date, new {
htmlAttributes = new { @readonly = "readonly" } })
</td>
<td>
@Html.TextBoxFor(model => model[i].studenttb.s_remarks)
</td>
<td>
<div class="col-md-10">
@Html.DropDownList("a_id" , null, htmlAttributes: new { @class =
"form-control" })
</div></td>
</tr>
}
}
Это результат просмотра страницы
Примечание. По сути, я хочу отправить несколько значений раскрывающегося списка контроллеру при нажатии кнопки Отправить.