我环顾四周,但找不到任何解决我(这个常见?)问题的问题。
我的问题是刷新了整个网站,而不仅仅是div标签。它已经工作了一次,但在更新后,不再是......
AddMember.cshtml
@using DBSUSite.ViewModels
@model CommitteeAddMemberModel
<script src='@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")' type="text/javascript"></script>
<h1>
Tilføj medlem</h1>
<p>
Her kan du søge efter brugere og tilføje dem til bestyrelsen eller udvalget.</p>
@using (Ajax.BeginForm("SearchMembers", new AjaxOptions { UpdateTargetId = "searchUsersList", HttpMethod = "POST" }))
{
@Html.HiddenFor(model => model.CommitteeId)
<label for="str">
Søg efter:
</label>
<input id="str" name="str" value="" />
<input type="submit" value="Søg" />
}
<div id="searchUsersList">
@{ Html.RenderPartial("_SearchUserPartial", Model); }
</div>
动作
[Authorize]
[HttpPost]
public ActionResult SearchMembers(int committeeId, string str)
{
//TODO: Put into User model!
var db = new DBEntities();
// Removed lots of code.
var model = new CommitteeAddMemberModel { CommitteeId = committeeId, Users = users.Values.AsEnumerable() };
return PartialView("_SearchUserPartial", model);
}
部分视图
@using DBSUSite.Models
@using DBSUSite.ViewModels
@model CommitteeAddMemberModel
<table>
<thead>
<tr>
<th>
Navn
</th>
<th>Tilføj</th>
</tr>
</thead>
<tbody>
@foreach (User user in Model.Users)
{
<tr>
<td>
@Html.DisplayFor(q => user.FirstName) @Html.DisplayFor(q => user.Surname)
</td>
<td>
@Html.ActionLink("Tilføj", "SaveMember", "Committee", new { committeeId = Model.CommitteeId, userId = user.UserID }, null)
</td>
</tr>
}
</tbody>
</table>
提前致谢!
答案 0 :(得分:1)
您需要确保包含 所有 这些库:
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>