我需要在编辑模式下保持学生的兴趣有部分视图,其中有两个列表框 - 一个用于当前兴趣,另一个用于可用(未添加到学生资料中)每个兴趣都有一个 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>
我必须将 model.StId 与 Ajax Actionlink 一起传递,例如 @Ajax.ActionLink("Add", "AddInterest", new { id = item.IsId, StId = @Model.StId },
在控制器中
public ActionResult AddInterest( int id, int StId)
{
//logic to add interest in specific student profile depend on StId
}