Question

I want to apply some custom render client (csr) to site column in XsltListViewWebPart with c# this is the code :

using (SPSite site = new SPSite("http://sharepoint"))
        {                               
            site.AllowUnsafeUpdates = true;

            SPField Status = web.Fields["Status"];

            Status.JSLink = "~site/_catalogs/masterpage/CustomField.js";
            Status.Update(true);
        }

I get this error Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.

SPSecurity.RunWithElevatedPrivileges doesn’t work either.

When I just add list view through the browser the CSR work perfectly but when I try to add list view through c#, the CSR doesn't work.

Thank in advance for your help.

Was it helpful?

Solution

I find this link which explain a similar problem, AllowUnsafeUpdates

Anyway, I have done that trough visual studio when I define the site column, I have add a csr file in layouts folder and apply through myview.jslink ="/_Layouts/15/csr/custom_field.js";

I think also this tutorial can help to use csr to custumize site column csr tutorial

  1. we can't apply xslt file and csr file on the same view. so I have removed the xslt file and combine javascript for the csr and css for the layouts.
  2. When you use xsltlistview from webpart (c#) you have to save the javascript file in the folder layouts. and the link for this file has to be /_Layouts/15/folder/myfile.js

I hope this is can help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top