This is a migrated thread and some comments may be shown as answers.
Providing data from C#
4 Answers 180 Views
This is a migrated thread and some comments may be shown as answers.
G S S
Top achievements
Rank 1
G S S asked on 18 Feb 2012, 06:57 PM
Hi,

With the uncertainty over sliverlight, I am focusing on html 5. However, html 5 does not seem to be able to fill the void of a server-side tech like silverlight (or so I think!).

Specifcally, with kendo UI, can I stream data to charts in a real time fashion with C#? I think I saw a thread about providing data from C# to Kendo UI?

Also, I would love to see the product be = to Kendo UI in terms of features and controls (E.g. the book control).



Thanks

4 Answers, 1 is accepted

Sort by
0
Gabriel
Top achievements
Rank 1
answered on 19 Feb 2012, 05:20 AM
You can use an ASP.NET web service written in C# or use the new Web API. I use the latter (with VB) with no problems at all.
0
G S S
Top achievements
Rank 1
answered on 20 Feb 2012, 11:36 AM
Thanks. Is there any example of this? I realise you're not a Telerik employee.
0
Gabriel
Top achievements
Rank 1
answered on 21 Feb 2012, 12:08 AM
This is the JavaScript I have for Autocomplete:
$("#txtSearch").kendoAutoComplete({
        change: onSearchClick,
        minLength: 3,
        dataTextField: "title",
        dataSource: new kendo.data.DataSource({
            type: "json",
            pageSize: 8,
            serverFiltering: true, // Required to prevent caching.
            serverPaging: true, // Required to prevent caching. 
            transport: {
                read: getRootDomain() + "/autoComplete",
                parameterMap: function (options) {
                    return $.extend(options, {
                        title: $("#txtSearch").data("kendoAutoComplete").value()
                    });
                }
            },
            error: function (e) {
                // do something
            }
        })
    });


This is the code for the service.
Imports System.Json
Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports WebMatrix.Data
 
<ServiceContract()>
Public Class Autocomplete
 
#Region "Public methods"
 
    <WebGet(UriTemplate:="")>
    Public Function [Get]() As JsonArray
 
        ' Vars.
        Dim context = System.Web.HttpContext.Current
        Dim query As String
        Dim db = Database.Open("ILTV")
 
        ' Find the top 10 matches for the partial title typed.
        query = "SELECT TOP 10 Title, SKU, Collection FROM Titles WHERE Title LIKE '%" & context.Request("title") & "%' ORDER BY Title ASC"
        Dim result = db.Query(query)
 
        ' Format results for the JSON parser.
        Dim results As New List(Of Suggestion)
        For Each r In result
            Dim s As New Suggestion With {.title = r.Title, .url = r.Collection & "/" & Utilities.GetFriendlyProductUrl(r.Title) & "/" & r.SKU.ToString.ToLower}
            results.Add(s)
        Next
 
        ' Encode the JSON array.
        Dim jString As String = System.Web.Helpers.Json.Encode(results)
        Return JsonArray.Parse(jString)
 
    End Function
 
#End Region
 
    ' todo: comment me!
    ' lowercase on purpose to make it niceer when parsed to JSON.
#Region "Data models"
 
    Public Class Suggestion
 
        Public Property title As String
        Public Property url As String
 
    End Class
 
#End Region
    
End Class


You will need to download the new Web API preview from wcf.codeplex.com from Microsoft. It is just a few references you need to add + a smidge of code to register the service. It is pretty straight-forward enough + there is loads of sample with the Web API. You can also not use WCF by just have a webpage that returns the data if you are using Web Pages Razor.
0
1zias01
Top achievements
Rank 2
answered on 21 Feb 2012, 12:12 AM
Here is an example I did using the AutoComplete control.

$(document).ready(function () {
 
    $("#SearchBox").kendoAutoComplete({
        minLength2,
        dataTextField"VenueName",
        template$('#tmplSearchResults').html(),
        dataSource: {
            type"json",
            severFilteringtrue,
            serverPagingtrue,
            transport: {
                read"Services/Businesses.asmx/GetBusinessVenueAddressContact",
                parameterMapfunction () {
                    return { venueName$('#SearchBox').val(), reviewStatusId'1' };
                }
            }
        }
    });



});

at the top of your Web Service (.asmx)  make sure you uncomment this line
[System.Web.Script.Services.ScriptService]

In my javascript code above, this is the path to your web service and the name of the Web Method that you are calling.  
Services/Businesses.asmx/GetBusinessVenueAddressContact

I've been using jQuery and services like this (including WCF Web API) for over a year now, creating RIAs similar to what you might create with Silverlight.  But I feel that this way is better and Silverlight is on the way out (if it ever got off the ground to begin with).


Hope that helps.
Asked by
G S S
Top achievements
Rank 1
Answers by
Gabriel
Top achievements
Rank 1
G S S
Top achievements
Rank 1
1zias01
Top achievements
Rank 2
Share this question
or