Mam widok wyświetlający wartość logiczną (obecnie domyślną wartość 0) w formacie pola w widoku, którego nie mogę sprawdzić, aby aktywować jako true, a także chcesz wprowadź tekst w polu wyniku, aby powrócić do kontrolera i zapisz obie zmiany w tabeli. Czy ktoś może wyjaśnić, co muszę zrobić, aby ta funkcjonalność działała, proszę.Włącz boolean i wprowadź tekst w widoku, a następnie wróć do kontrolera - MVC
kod Kontroler
public ActionResult P1A1Mark()
{
List<MarkModel> query = (from row in db.submits
where row.assignment_no.Equals("1") && row.group_no == 1
group row by new { row.assignment_no, row.student_no, row.student.firstname, row.student.surname } into g
select new MarkModel
{
student_no = g.Key.student_no,
student_surname = g.Key.surname,
student_firstname = g.Key.firstname
}
).ToList();
return View(query);
}
Zobacz
@model IEnumerable<MvcApplication2.Models.MarkModel>
@{
ViewBag.Title = "P1A1Mark";
}
<h2>Mark Student Assignments</h2>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.student_no)
</th>
<th>
@Html.DisplayNameFor(model => model.student_surname)
</th>
<th>
@Html.DisplayNameFor(model => model.student_firstname)
</th>
<th>
@Html.DisplayNameFor(model => model.submitted)
</th>
<th>
@Html.DisplayNameFor(model => model.result)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.student_no)
</td>
<td>
@Html.DisplayFor(modelItem => item.student_surname)
</td>
<td>
@Html.DisplayFor(modelItem => item.student_firstname)
</td>
<td>
@Html.DisplayFor(modelItem => item.submitted)
</td>
<td>
@Html.DisplayFor(modelItem => item.result)
</td>
</tr>
}
</table>
model
public class MarkModel
{
public string student_no { get; set; }
public string student_surname { get; set; }
public string student_firstname { get; set; }
public string assignment_no { get; set; }
public bool submitted { get; set; }
public string result { get; set; }
public Nullable<int> group_no { get; set; }
}
'@ Html.DisplayFor (modelItem => item.result) -> @ Html.TextBoxFor (pozycja => item.result)' – Igor
dzięki @Igor, każdy pomysł na to, co zrobić z logiczną? – cg91
Myślę, że jesteś trochę za daleko, aby uzyskać prostą odpowiedź. Nawet jeśli możesz zaznaczyć to pole i wpisać wynik, musisz przepisać większą część widoku i napisać cały kod kontrolera. Istnieje wiele przykładów edycji listy obiektów, możesz przeszukać "Edytuj listę MVC" i znaleźć taką, która pomaga – JamieD77