Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在提供商托管的SharePoint应用程序中从JavaScript调用服务器端代码?_Javascript_C#_Angularjs_Sharepoint_Single Page Application - Fatal编程技术网

如何在提供商托管的SharePoint应用程序中从JavaScript调用服务器端代码?

如何在提供商托管的SharePoint应用程序中从JavaScript调用服务器端代码?,javascript,c#,angularjs,sharepoint,single-page-application,Javascript,C#,Angularjs,Sharepoint,Single Page Application,我正在为SharePoint开发一个提供商托管的应用程序,我使用nuget的“热毛巾角”包创建了一个水疗中心。据我所知,由提供商托管的应用程序的一个主要好处是能够执行服务器端代码。我的问题是:如何在水疗中心做到这一点 这是我的尝试: 在index.cshtml中 @Html.ActionLink("RunWithElevatedPrivileges", "RunWithElevatedPrivileges", "Employee") 在EmployeeController.cs中

我正在为SharePoint开发一个提供商托管的应用程序,我使用nuget的“热毛巾角”包创建了一个水疗中心。据我所知,由提供商托管的应用程序的一个主要好处是能够执行服务器端代码。我的问题是:如何在水疗中心做到这一点

这是我的尝试: 在index.cshtml中

@Html.ActionLink("RunWithElevatedPrivileges", "RunWithElevatedPrivileges", "Employee")
在EmployeeController.cs中

        public ActionResult RunWithElevatedPrivileges()
    {
        var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

        //using (var clientContext = spContext.CreateUserClientContextForSPHost())
        using (var clientContext = spContext.CreateAppOnlyClientContextForSPHost())
        {
            if (clientContext != null)
            {
                Web web = clientContext.Web;
                clientContext.Load(web);
                clientContext.ExecuteQuery();

                List list = clientContext.Web.Lists.GetByTitle("MyList3");
                ListItemCreationInformation info = new ListItemCreationInformation();
                Microsoft.SharePoint.Client.ListItem item = list.AddItem(info);
                item["Title"] = "Created from CSOM";

                item.Update();
                clientContext.Load(item);
                clientContext.ExecuteQuery();
            }
        }

        return View("ItemCreated");
    }
有没有一个像样的解决方案可以在不改变视图的情况下从JavaScript执行代码?我想用Angular和JavaScript编写我的解决方案,只在必要时调用C代码