編集モードで学生の関心を維持する必要があります。2つのリストボックスがある部分的なビューがあります。1つは現在の関心用で、もう1つは利用可能(学生のプロファイルには追加されません)用です。各関心にはajaxアクションリンクがあります。私がそれをクリックすると、それは学生の現在の興味に追加されます。問題は、-親ビューから(つまり、部分ビューからではなく)の学生IDを送信する必要があり、学生IDがURLにあるか-部分ビューで学生IDにアクセスするにはどうすればよいですか?
//コードサンプル
@model StdMan.Models.Student
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="../../../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Project</legend>
<div class="editor-label">
@Html.LabelFor(model => model.StId)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.StId)
@Html.ValidationMessageFor(model => model.StId)
</div>
<div class="editor-label">
Intested In
</div>
<div class="editor-field" id="Interest">
@Html.Action("PartialAddInterest", "Interest")
</div>
</fieldset>
<p>
<input type="submit" value="Save" />
</p>
}
////////// --PartialView PartialAddInterest.cshtml
@model IEnumerable<StdMan.Models.Interest>
<table>
@foreach (var item in ViewBag.Added)
{
<tr>
<td>@item.Name
@Ajax.ActionLink("Remove", "RemoveInterest",new { id = item.IsId },
new AjaxOptions
{
UpdateTargetId = "Interest",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
})
</td>
</tr>
}
</table>
<table>
@foreach (var item in ViewBag.Rem)
{
<tr>
<td>@item.Name
@Ajax.ActionLink("Add", "AddInterest", new { id = item.IsId },
new AjaxOptions
{
UpdateTargetId = "Interest",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
})
</td>
</tr>
}
</table>
@ Ajax.ActionLink( "Add"、 "AddInterest"、new {id = item.IsId、StId = @ Model.StId}、のようなAjaxActionlinkでmodel.StIdを渡す必要があります
コントローラー内
public ActionResult AddInterest( int id, int StId)
{
//logic to add interest in specific student profile depend on StId
}