【发布时间】:2018-08-05 16:37:33
【问题描述】:
我从 SharePoint 获取列表并将其保存到 C# 列表中。我将该列表发送到 PartialView 并执行 Foreach 以显示带有包含其 ID 的编辑按钮的项目。
return PartialView("IRFList", items);
<h5>@Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "badge badge-primary editIRFBut" })</h5>
PartialView 加载到索引主体上。如果我单击编辑,让我编辑页面,一切正常。 我还有一个“新项目”按钮,它使用 $.post 来联系创建项目的 AddItem 控制器。成功后我重新加载部分视图 ->
$.ajax({
url: listUrl,
type: "GET",
dataType: "html",
success: function (data) {
$('.irfListPartial').html(data);
},
});
一切正常,但 PartialView 重新加载后我的链接按钮出现问题。
我的网址类似于“example.com?SPHostUrl=https.....”。当我第一次加载索引时,编辑按钮包含“?SPHostUrl”,但是当我重新加载 PartialView 时,它们会丢失 URL 的那部分。
我实际上需要该 URL 来调用 sharepoint,我的问题是.... 重新加载部分视图后,如何确保我的编辑按钮链接在其 URL 中包含 ?SPHostUrl?
编辑:根据 Shyju 的回答进行了更新以便于阅读。
public ActionResult IRFList()
{
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
List<IRFItem> items = SharepointService.GetItems(spContext);
ViewBag.SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri;
return PartialView("IRFList", items);
}
对于部分编辑按钮
<h5>@Html.ActionLink("Edit", "Edit", new { id = item.Id, SPHostUrl = ViewBag.SPHostUrl }, new { @class = "badge badge-primary editIRFBut" })</h5>
【问题讨论】:
-
您需要将其发送到您的控制器并将其添加到链接参数中,或者在将 html 注入
.irfListPartial之前在客户端执行此操作
标签: c# asp.net-mvc