私はプログラミングが初めてで、問題に悩まされています。
mvc と asp.net を使用して、データベースの複数の行を 1 つのビューで編集および更新しようとしています。私は正しい軌道に沿っていると思いますが、「すべてのコードパスが値を返すわけではありません」というエラーが表示され続けます。私のコントローラーは次のようになります。
[HttpGet]
public ViewResult AnotherListEdit()
{
var chosenClass = from c in db.ClassInstanceDetails.Include("ClassInstance").Include("Student")
where c.ClassInstance.ID == 1
select c;
return View(chosenClass.ToList());
}
[HttpPost]
public ActionResult AnotherListEdit(IList<ClassInstanceDetail> list)
{
if (ModelState.IsValid)
{
foreach (ClassInstanceDetail editedClassInstanceDetail in list)
{
var tempBook = (from classInstDet in db.ClassInstanceDetails
where (teacher.ClassInstanceID == editedClassInstanceDetail.ClassInstanceID)
&& (classInstDet.StudentID == editedClassInstanceDetail.StudentID)
select teacher).First();
db.ApplyCurrentValues(tempBook.EntityKey.EntitySetName, editedClassInstanceDetail);
}
db.SaveChanges();
return View(db.Teachers.ToList());
}
}
私のビューは次のようになります。
@model IList<FYPSchoolApp.DAL.ClassInstanceDetail>
@{
ViewBag.Title = "AnotherListEdit";
}
@using (Html.BeginForm())
{
<table>
<tr>
<th>
Name
</th>
<th>
Second Name
</th>
<th>
attendance
</th>
<th>
Comment
</th>
</tr>
@for (var i = 0; i < Model.Count(); i++) {
<tr>
<td>
@Html.DisplayFor(m => Model[i].StudentID)
</td>
<td>
@Html.DisplayFor(m => Model[i].Attendance)
@Html.EditorFor(m => Model[i].Attendance)
</td>
<td>
@Html.DisplayFor(m => Model[i].CommentNote)
@Html.EditorFor(m => Model[i].CommentNote)
</td>
</tr>
}
</table>
<input type="submit" value="save" />
}
「すべてのコード パスが値エラーを返すわけではない」は、AnotherListEdit 関数で強調表示されています。その機能全体を使用せずにプロジェクトを実行すると、ディスプレイが機能し、正しい情報がディスプレイに渡されます。
どんな助けでも大歓迎です!!