Telerik Forums
UI for ASP.NET MVC Forum
1 answer
13 views

Hi,

I have a problem displaying the content from the AIPrompt Output tab and I'm getting An error occurred while processing the request.

I'm not sure if I'm missing a parameter returning  the response from the content. I am using OpenAI as a service.

  • Here is my code

public async Task<ActionResult> GenerateSupplierAIReponse()
{
    var apiKey = ConfigurationManager.AppSettings["OpenAPIKey"];
    var aiServiceUrl = "https://api.openai.com/v1/chat/completions";
    StringBuilder sb = new StringBuilder();
    using (var httpClient = new HttpClient())
    {
        httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiKey);

        try
        {
            using (var requestStream = new StreamReader(HttpContext.Request.InputStream))
            {
                var body = await requestStream.ReadToEndAsync();
                var requestBody = new
                {
                    model = "gpt-4",
                    messages = new[]
                    {
                        new { role = "user", content = body }
                    }
                };

                var response = await httpClient.PostAsJsonAsync(aiServiceUrl, requestBody);
             
                response.EnsureSuccessStatusCode();
                var jsonResponse = await response.Content.ReadAsStringAsync();
                OpenAIResponse aIResponse = JsonConvert.DeserializeObject<OpenAIResponse>(jsonResponse);


                foreach (var i in aIResponse.choices)
                {
                    sb.AppendLine(i.message.content);
                }

                var formattedResponse = new
                {
                    Output = sb.ToString(),
                };

                string finalJsonResult = new JavaScriptSerializer().Serialize(formattedResponse);
                return Content(finalJsonResult, "application/json");
            }

        }
        catch (HttpRequestException ex)
        {
            // Log the error
            Console.Error.WriteLine($"HTTP Error: {ex.Message}");
            return Json(new { error = "Error communicating with OpenAI." }, JsonRequestBehavior.AllowGet);
        }
        catch (Exception ex)
        {
            // Log the error
            Console.Error.WriteLine($"General Error: {ex.Message}");
            return Json(new { error = "An unexpected error occurred." }, JsonRequestBehavior.AllowGet);
        }
    }

}

 

  • Here is the example content that I'm about to return.

"{\"Output\":\"As an AI, I don\\u0027t have real-time data access, but as of my last update, I don\\u0027t have specific information about the parent company of Acme Electronics. Acme is a common generic name used in various forms of fiction, and there could be many small companies by that name. It would help if you were more specific about the company\\u0027s location or other details.\\r\\n\"}"

 

  • and here is my UI
@(Html.Kendo().AIPrompt()
    .Name("aiprompt")
    .ActiveView(0)
    .Service("GenerateSupplierAIReponse", "Supplier")
    //.Events(events => events
    //    .PromptRequest("onPromptRequest")
    //)
    .ToolbarItems(items =>
    {
        items.Add().Type(ItemType.Spacer);

        items.Add()
             .Type(ItemType.Button)
             .Icon("x")
             .FillMode(ButtonFillMode.Flat)
             .Rounded(Rounded.Full)
             .ThemeColor(ThemeColor.Primary)
             .Click("onToolbarButtonClick");
    })
    .Views(views =>
    {
        views.Add().Type(Kendo.Mvc.UI.ViewType.Prompt)
        .PromptSuggestions(new string[] { "What is the parent company of " + Model.Name, "Give me the headquarter address of " + Model.Name });
        views.Add().Type(Kendo.Mvc.UI.ViewType.Output);
    })
)

 

  • and here is the result

Everything is getting all the correct authentication and the ai response message content but upon returning the content it will prompt an error message. 

Please advice.

Thank you,

Gerber Manalo


 

Gerber
Top achievements
Rank 1
Iron
 answered on 22 May 2025
1 answer
31 views

Hi,

We are using Kendo controls for MVC. There was a security scan done in our application, it capture few of the security issues.

We are able to fix all of the security issues except one.

CWE 829 - The application contains unsafe Content-Security-Policy (CSP) directives that could allow malicious script code to be included on the page.

So, as a result we have removed all the custom inline javascript and css to an external files and refer those external .js and .css files in our .cshtml page.

But when we use any of the Kendo controls like Kendo grid or Kendo calendar then in the runtime it create some inline scripts and we are getting application contains unsafe Content-Security-Policy (CSP) directives.

How to bypass those runtime inline scripts created by Kendo controls so that we don't get unsafe Content-Security-Policy (CSP) directives

during the security scan of the application.

Please let me know if you need any more information on this.

1 answer
17 views

I'm encountering an issue with the Kendo UI Form when using a MultiSelect widget. When I render a form that includes a single MultiSelect field bound to a value, the widget inexplicably displays two chips for that value.

Key Observations:

  • This occurs with both single and multiple selections.

  • The issue does not occur when the MultiSelect is used outside the context of a Kendo Form.

  • I'm fairly certain this is related to how the form is configured or how the binding is set up.

  • I've reduced my code to a minimal test case to replicate the issue.

  • See attached screenshots for reference.

Question:

Has anyone else encountered this behavior when using a MultiSelect within a Kendo UI Form? Any tips on what might be causing the duplicate value chips?

Thank you in advance! :)

 public class TestViewModel
 {
     public List<string> SelectedItems { get; set; } = new List<string>();
     public List<string> AvailableItems { get; set; } = new List<string>();
 }
public class TestController : Controller
{
    public ActionResult Index()
    {
        var model = new TestViewModel
        {
            AvailableItems = ["Option A", "Option B", "Option C"],
            SelectedItems  = []
        };
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(TestViewModel model)
    {
        model.AvailableItems = ["Option A", "Option B", "Option C"];
        return View(model);
    }
}
@(Html.Kendo().Form<TestViewModel>()
    .Name("testForm")
    .HtmlAttributes(new { method = "post", id = "testForm" })
    .Items(items =>
    {
        items.AddGroup()
             .Label("Demo")
             .Items(g =>
             {
                 g.Add().Field(m => m.SelectedItems)
                      .Label("Pick Items")
                      .Editor(e => e.MultiSelect()
                          .BindTo(Model.AvailableItems)
                          .Placeholder("Select…")
                      );
             });
    })
)



Ivaylo
Telerik team
 answered on 16 May 2025
0 answers
21 views

Hi,

wie have a Model A which is related to Model B (1:n). Both have a field of type DateTime with the DisplayFormat-Annotation '[DisplayFormat(DataFormatString = "{0:d}")]'.

If we display both fields in the Details-View of Model A, the formats are applied correctly.

If we display bot fields in a Telerik-GridView, only the format for Model A is applied. Model B shows something like '/Date(1741302000000)/'.

It's important to note, that our application is multilanguage, and we have to support different data formats for each language.

 

How would we go about this? Is this known behaviour?

Stefan
Top achievements
Rank 1
Iron
Iron
Iron
 asked on 14 May 2025
1 answer
44 views

I have a ListView that works very nicely with most of the default behavior as shown below.  However, I would like to create a new item in the ListView by using a Popup form.  This form could also be used by the edit event if that simplifies the code, but does not have to be the same, and the edit functionality could work as it does now.  I have looked at the popup editing feature as described here.  However, I could not figure out how to make this work for create as there is no create event on the ListView.  Does everything have to work outside the framework of the control, so that the add is using a separate Ajax call and then refreshing the view, or is there a better way to keep this within the structure of the ListView and its events?

Add Button and ListView:

            @(Html.Kendo().Button()
                .Name("AddNew")
                .Icon("plus")
                .FillMode(ButtonFillMode.Solid)
                .Rounded(Rounded.Medium)
                .HtmlAttributes(new { @class = "add-button" })
                .Events(e=>e.Click("addNewClick"))
            )

            @(Html.Kendo().ListView<MyNamespace.Models.ItemComment>()
                .Name("listView")
                .TagName("div")
                .ClientTemplateId("commentListTemplate")
                .Editable()
                .DataSource(dataSource => dataSource
                    .Model(model => model.Id(comment => comment.CommentID))
                    .Read(read => read.Action("Comments_Read", "Comment").Data("getCommentReadParameters"))
                    .Update(update => update.Action("Comments_Update", "Comment"))
                    .Destroy(destroy => destroy.Action("Comments_Delete", "Comment"))
                    .Events(e => e.Error("epic.error.kendoErrorHandler"))
                )
                .Events(e => e.DataBound("onCommentsDataBound"))
                .Events(e => e.Remove("deleteConfirmation"))

            )

Display Template:

<script type="text/x-kendo-tmpl" id="commentListTemplate">
     <div class="k-card">
            <div class="k-card-body k-card-horizontal k-vbox k-column" style="margin:0;padding:4px 4px 0">
                <img class='k-card-image' style="height:16px; margin-right:5px;" src="@Url.Content("~/Content/assets/images/blue-person.png")">
                <div class='commentHeader'>
                    <h6 class='k-card-subtitle'>#= UserID #</h6>
                    <div class="edit-buttons">
                        <a role="button" class="k-button k-button-solid-base k-button-solid k-button-md k-rounded-md k-edit-button" href="\\#">#= kendo.ui.icon({ icon: 'pencil' }) #</a>
                        <a role="button" class="k-button k-button-solid-base k-button-solid k-button-md k-rounded-md k-delete-button" href="\\#">#= kendo.ui.icon({ icon: 'x' }) #</a>
                    </div>
                    <p>
                        #: Comment #
                    </p>
                </div>
            </div>
    </div>
</script>

Supporting JavaScript functions:

<script type="text/javascript">

    function onCommentsDataBound() {
        if (this.dataSource.data().length == 0) {
            $("#listView").append("<h3 style='padding: 2px 4px 0;'>No comments</h3>");
        }
    }

    function addNewClick(e) {
        var listView = $("#listView").data("kendoListView");
        listView.add();
        e.preventDefault();
    }

    function deleteConfirmation(event) {

        if (!confirm("Are you sure you want to delete this comment?"))
            event.preventDefault();
    }

</script>

Thanks, Bob

 

Eyup
Telerik team
 answered on 07 May 2025
1 answer
29 views
      Error CS0234: The type or namespace name 'FileBrowserController' does not exist in the namespace 'Kendo.Mvc.UI' (are you missing an assembly reference?) (15, 55)
      Error CS0246: The type or namespace name 'EditorImageBrowserController' could not be found (are you missing a using directive or an assembly reference?) (16, 43)
Mihaela
Telerik team
 answered on 07 May 2025
0 answers
19 views
Hi Team,
I am using the Spreadsheet module for ASP.NET Core.
Currently, we can add a dropdown to a specific spreadsheet cell using (https://demos.telerik.com/aspnet-core/spreadsheet/custom-editors).
However, I would like to add a dropdown to an entire column without having to manually add it to each row or cell through code.
Could you please check if this is possible?
Rakesh
Top achievements
Rank 1
 asked on 07 May 2025
1 answer
16 views

I am trying to implement a custom tool in the Kendo Editor, following demo/doc implementation and always getting a typeError of some form whenever the custom tool uses a kendo template.  For example:

@(Html.Kendo().Editor()
    .Name("editor")
    .Tools(tools => {
            tools
        .Clear()
        .Bold()
        .Italic()
        .CustomTemplate(temp => temp.Template(
                Html.Kendo().DropDownList()
                    .Name("ddl1")
                    .DataTextField("Text")
                    .DataValueField("Value")
                    .BindTo(new List<object>
                    {
                        new { Text = "text 1", Value = "Value 1" },
                        new { Text = "text 2", Value = "Value 2" },
                        new { Text = "text 3", Value = "Value 3" },
                        new { Text = "text 4", Value = "Value 4" }
                    })
                    .ToClientTemplate()
                    .ToHtmlString()
                ));
    })
)

In this case the error is as follows:

Uncaught TypeError: Cannot read properties of null (reading 'length')

Mihaela
Telerik team
 answered on 05 May 2025
1 answer
22 views

We are using KendoEditor in our MVC application. When assigend HTML to it it is auto formatting it. E.g.
<p style="font-size:13.3333px;"><span style="font-family:Verdana, Geneva, sans-serif;font-size:14pt;">Dear ABC</></></></span></p><p style="font-size:13.3333px;"><span style="font-family:Verdana, Geneva, sans-serif;font-size:14pt;">We have received your details:&nbsp;</span><span style="color:#ffffff;"><span id="spa123"><span> Certificates</span><table class="tbl" border="1" cellpadding="1" cellspacing="0" style="width:100%;font-family:inherit;font-size:inherit;color:inherit;" ><tr style="font-weight:bold;"><td style="text-align: right">Id</td><td style="text-align: left">name</td><td style="text-align: left">Amount</td><td style="text-align: left">Other</td><td style="text-align: left">Comments</td></tr><tr><td style="text-align: right;">1</td><td style="text-align: left;"></td><td style="text-align: left;"></td><td style="text-align: left;"></td><td style="text-align: left;"></td></tr></table></span></span> <span style="background-color:#ffffff;color:#ffffff;"></span></p>

changing to 

<p style="font-size:13.3333px;"><span style="font-family:Verdana, Geneva, sans-serif;font-size:14pt;">Dear ABC</span></p>
<p style="font-size:13.3333px;"><span style="font-family:Verdana, Geneva, sans-serif;font-size:14pt;">We have received your details:&nbsp;</span><span style="color:#ffffff;"><span id="spa123"><span>Certificates</span></span></span></p>
<table class="tbl k-table" border="1" cellpadding="1" cellspacing="0" style="width:100%;font-family:inherit;font-size:inherit;color:inherit;"><tbody><tr style="font-weight:bold;"><td style="text-align:right;">Id</td>
<td style="text-align:left;">name</td>
<td style="text-align:left;">Amount</td>
<td style="text-align:left;">Other</td>
<td style="text-align:left;">Comments</td>
</tr>
<tr><td style="text-align:right;">1</td>
<td style="text-align:left;">&nbsp;</td>
<td style="text-align:left;">&nbsp;</td>
<td style="text-align:left;">&nbsp;</td>
<td style="text-align:left;">&nbsp;</td>
</tr>
</tbody></table>
<span style="background-color:#ffffff;color:#ffffff;"></span><p>&nbsp;</p>

Here <span> and <P> tags automatically getting closed before table. while extected is all should be in span with <span style="color:#ffffff;">.

 

Not able to trace why it is happning.

Anton Mironov
Telerik team
 answered on 29 Apr 2025
1 answer
41 views

Hello,

I'm fairly new to Kendo and having an issue when attempting to pass a CustomerID to a TabStrip from a Grid.

Based on the following article I have tried to follow to get Order data loaded on the TabStrip however I'm running into the below JavaScript error

https://demos.telerik.com/aspnet-core/grid/detailtemplate

Syntax error, unrecognized expression: #tabStrip_#=CustomerID# & Uncaught Error: Syntax error, unrecognized expression: #grid_#=CustomerID#

Please see Grid and TabStrip code below.

@(Html.Kendo().Grid<LewisTestProject.Models.Customer>()
  .Name("grid")
  .DataSource(dataSource => dataSource
      .Ajax()
      .Model(model => {
          model.Id(p => p.CustomerID);
          model.Field(p => p.CustomerID).Editable(false);
      })
      .PageSize(18)
      .Read(read => read.Action("Customers_Read", "Customer"))
      .Create(create => create.Action("Customers_Create", "Customer"))
      .Update(update => update.Action("Customers_Update", "Customer"))
      .Destroy(destroy => destroy.Action("Customers_Destroy", "Customer"))

   )
  .Columns(columns =>
  {
      columns.Bound(order => order.CustomerID);
      columns.Bound(order => order.CompanyName);
      columns.Bound(order => order.ContactName);
      columns.Bound(order => order.ContactTitle);
      columns.Bound(order => order.Address);
      columns.Bound(order => order.City);
      columns.Bound(order => order.Region);
      columns.Bound(order => order.PostalCode);
      columns.Bound(order => order.Country);
      columns.Bound(order => order.Phone);
      columns.Bound(order => order.Fax);
      columns.Command(command =>
      {
          command.Edit();
          command.Destroy();
      }
      ).Title("Actions");
  })
  .ToolBar(toolbar => {
      toolbar.Create();
      toolbar.Search();
  })
  .Pageable()
  .Sortable()
  .ClientDetailTemplateId("template")
  .Events(events => events.DataBound("dataBound"))
  .Editable(e => e.Mode(GridEditMode.InLine))
 )
<script id="template" type="text/kendo-tmpl">
@(Html.Kendo().TabStrip()
    .Name("tabStrip_#=CustomerID#")
    .SelectedIndex(0)
    .Animation(animation => animation.Open(open => open.Fade(FadeDirection.In)))
    .Items(items =>
    {
        items.Add().Text("Orders").Content(@<text>
            @(Html.Kendo().Grid<LewisTestProject.Models.OrderViewModel>()
                .Name("grid_#=CustomerID#") // template expression, to be evaluated in the master context
                .Columns(columns =>
                {
                    columns.Bound(o => o.CustomerID);
                    columns.Bound(o => o.OrderID).Title("ID").Width(100);
                })
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(5)
                    .Read(read => read.Action("OrdersDetail_Read", "Customers", new { customerID = "#=CustomerID#" }))
                )
                .Pageable()
                .Sortable()
                .ToClientTemplate()
                )
        </text>
        );
        //items.Add().Text("Contact Information").Content(
        //    "<div class='employee-details'>" +
        //        "<ul>" +
        //            "<li><label>Country:</label>#= Country #</li>" +
        //            "<li><label>City:</label>#= City #</li>" +
        //            "<li><label>Address:</label>#= Address #</li>" +
        //            "<li><label>Home Phone:</label>#= Phone #</li>" +
        //        "</ul>" +
        //    "</div>"
        //);
    })
    .ToClientTemplate()
    )
</script>

Any help would be greatly appreciated.

Thanks,

Lewis.

Anton Mironov
Telerik team
 answered on 28 Apr 2025
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?