Dear Syncfusion team,
I've been trying for a long time to connect the SfGrid with the SfDatamanager and the WebApiAdaptor.
Everything works fine, but when I set the ApiController to [Authorize ()], I don't get any more data.
namespace MyBlazorWebApiTest.Controller
{
[Route("api/[controller]")]
[ApiController]
[Authorize()]
public class CustomerController
{
[HttpGet]
public object Get()
{
var l = GetSampleData();
var tt = new { Items = l, Count = l.Count };
return tt;
}
public static List<Customer>GetSampleData()
{
var l = new List<Customer>();
l.Add(new() { ID = 1, Firstname = "Lin", Lastname = "Love" });
l.Add(new() { ID = 2, Firstname = "Mike", Lastname = "Mutz" });
l.Add(new() { ID = 3, Firstname = "Nils", Lastname = "None" });
l.Add(new() { ID = 4, Firstname = "Poke", Lastname = "Port" });
return l;
}
}
}
My Grid:
<sfgrid tvalue="Customer" toolbar="@(new List<string>() { " add",="" "edit",="" "delete"="" })"="">
<sfdatamanager url="/api/customer" adaptor="Adaptors.WebApiAdaptor"></sfdatamanager>
<gridcolumns>
<gridcolumn field="@nameof(Customer.ID)"></gridcolumn>
<gridcolumn field="@nameof(Customer.Firstname)"></gridcolumn>
<gridcolumn field="@nameof(Customer.Lastname)"></gridcolumn>
</gridcolumns>
</sfgrid>
Hi Rahul
Thank you for your quick reply.
I have now again spent hours trying to find a solution. Sure it's very simple, but I can't figure it out.
I have attached Sampleproject with the problem on the /Index page.
Can you please help me?
Regards
Chris
Hi Rahul,
Thank you for your reply.
You wrote: The data was not loaded in the Grid and the controller is not even triggered after removing [Authorize].
I have downloaded the project again and when I remove the [Authorize()] anotation in the file: /Controller/CustomerController.cs the grid loads the data. I have attached the project where I made just thi single change.
You wrote: Could you please share the below details. It will be helpful to proceed this problem further.
<SfDataManager Headers=@HeaderData Url="@OdataUrl" Adaptor="Adaptors.WebApiAdaptor"></SfDataManager>
... @code{
private IDictionary<string, string> HeaderData = new Dictionary<string, string>();
protected override void OnInitialized()
{
HeaderData.Add("Bearer", "{your_auth_token}");
}
|
|
public class CustomerController
{
[HttpGet]
[AllowAnonymous]
public object Get()
{
var l = GetSampleData();
var tt = new { Items = l, Count = l.Count };
return tt;
}
|