現在、利用可能なすべてのユーザーを一覧表示する次の部分ビューと、各ユーザーの横にある[クラスにユーザーを追加]リンクを使用して、ユーザーをクラスに登録しています。
@model IEnumerable<Elearning.Models.User>
<tr>
<th>
Student ID
</th>
</tr>
@foreach (var item in Model) {
<tr >
<td>
@Html.DisplayFor(modelItem => item.UserID)
</td>
<td id = "userclass">
@Ajax.ActionLink("Add User to Class", "Register", "User", new { id = item.UserID, classid = ViewBag.id },
new AjaxOptions {
InsertionMode = InsertionMode.InsertAfter,
HttpMethod = "POST",
UpdateTargetId = "incrementadd"
})
</td>
</tr>
}
[クラスにユーザーを追加]リンクをクリックしたときに呼び出されるアクションメソッドは次のとおりです。-
[AcceptVerbs(HttpVerbs.Post)]
public PartialViewResult Register(string id, int classid)
{
try
{
//Update code here
User user = r.FindUser(id);
Users_Classes uc = new Users_Classes();
uc.AddedDate = DateTime.Now;
uc.ClassID = classid;
user.Users_Classes.Add(uc);
r.Save();
ViewBag.classid = classid;
return PartialView("_usersearch2", uc);
}
}
上記のコードは正常に機能していますが、リンクをクリックして各ユーザーを追加するのは簡単ではありません。だから私はユーザーの選択に基づいてユーザーを登録および登録解除するための追加/削除ボタンでリストボックスを追加しようとしていますが、Jqueryを使用して「追加/削除」ボタンでリストボックスを実装するためにコードを変更する方法を理解できません私のシステムをよりユーザーフレンドリーにします。誰かが私の開発に役立つ資料やサンプルコードを紹介してくれますか?よろしくお願いします