I try to use the Kendo UI Autocomplete tool with a C# datasource.
It seems very easy in PHP:
<?php
include("connection.php");
$arr = array();
$stmt = $db->prepare("SELECT StateID, StateName FROM USStates WHERE StateName LIKE ?");
// get the StartsWith value and append a % wildcard on the end
if ($stmt->execute(array($_GET["StartsWith"]. "%"))) {
while ($row = $stmt->fetch()) {
$arr[] = $row;
}
}
// add the header line to specify that the content type is JSON
header("Content-type: application/json");
echo "{\"data\":" .json_encode($arr). "}";
?>
But I want to use a CSHtml file or something equivalent, do you have any idea on how to accomplish this?
I don’t want to create a controller attached with a model, etc… If it’s possible to make it with only one page, it would be great.
If you are using MVC Create a controller like so….
Then all you have to do is set the datasource url to /data/GetStates
If you are using webforms I would create a generic handler or a webservice (depending on how many functions you need)
For completness sake.. here is how you would pull off the same using a ashx webservice