I am using ASP.NET MVC 3 with the razor view engine.
I have the following method in my NewsController:
public JsonResult GetAllNews()
{
var items = newsService.FindAll();
var jsonResult = Json(items);
return jsonResult;
}
In my view I want to try and call this method to populate my YUI datatable. I put a breakpoint on the first line of this method but the breakpoint is not hit. Here is my code in the view to call this method:
var newsDataSource = YAHOO.util.DataSource('@Url.Action("GetAllNews");');
I even tried:
var newsDataSource = YAHOO.util.DataSource("/News/GetAllNews/");
Both don't seem to work.
Here is my datatable code:
<div id="grdNews"></div>
<script type="text/javascript">
// News grid
var newsColumnDefs = [
{ key: "id", label: "Identifier" },
{ key: "title", label: "Title" },
{ key: "body", label: "Body" }
];
//var newsDataSource = YAHOO.util.DataSource('@Url.Action("GetAllNews");');
var newsDataSource = YAHOO.util.DataSource("/News/GetAllNews/");
newsDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
newsDataSource.responseSchema = {
fields: [
{ key: "id" },
{ key: "title" },
{ key: "body" }
]
};
var myDataTable = new YAHOO.widget.DataTable("grdNews", newsColumnDefs, newsDataSource);
</script>
What am I doing wrong?