WCF Data Services instance: Asp.net Ajax access

Source: Internet
Author: User

This document provides a reference example based on the Code. msdn example,CodePlaced in:

Http://dskit.codeplex.com

To access the WCF data service using JavaScript in the Asp.net MVC application, the following is an example of using the Microsoft Ajax library for processing.

var datacontext;
var queryobject, queryobject1;
sys. require ([sys. components. dataview, sys. components. adonetdatacontext]);
// run the command
sys. onready (function () {
datacontext = sys. create. adonetdatacontext (
{< br> serviceuri: "/services/northwindservice. SVC ",
mergeoption: SYS. data. mergeoption. appendonly
});
datacontext. initialize ();
queryobject = new sys. data. adonetquerybuilder ("customers");
queryobject. set_orderby ("contactname"); // $ orderby
queryobject. set_filter ("city EQ" + "'London"); // $ filter
queryobject. set_expand ("orders"); // $ expand
queryobject1 = new sys. data. adonetquerybuilder ("customers");
queryobject1.set _ filter ("startswith (companyName, 'A')");

});
 
<Body xmlns: dataview = "javascript: SYS. UI. dataview" xmlns: SYS = "javascript: SYS">
<Table>
<Tr class = "tableheader">
<TD>
ID
</TD>
<TD>
Name
</TD>
<TD>
Contact
</TD>
<TD>
# Orders
</TD>
</Tr>
<Tbody SYS: attach = "dataview" class = "sys-template" dataview: dataprovider = "{datacontext }}"
Dataview: fetchoperation = "{queryobject. tostring ()}" dataview: autofetch = "true">
<Tr>
<TD>
{Customerid }}
</TD>
<TD>
{CompanyName }}
</TD>
<TD>
{Contactname }}
</TD>
<TD>
{Orders. Length }}
</TD>
</Tr>
</Tbody>
</Table>

The above code is in the upper part.

It is a demonstration of three scenarios: Table display, query, and Master/Slave tables. It can be seen that the client script library of Ms Ajax has powerful functions.

Face-to-Face table display can be customized using CSS control. Of course, there are also many frame libraries, such as jqgrid in jquery.

If you are integrated with Asp.net, you can use jqmvcgrid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.