Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,

I have created Web API in Asp.net MVC4.
I have used entity frame work.As i am able to get data in Json but i am not able to integrate those data with my HTML page.
I have used kendo UI control (List view) in html page.

This is the I have written in Controller:

C#
 public HttpResponseMessage get123()
        {
            return Request.CreateResponse(HttpStatusCode.OK, userlist());
        }


/-----To Get list of users-----/       
   
    private IEnumerable<userinfo> userlist()
        {
            userinfo[] list;
           using (var context = new Assignment_dbEntities())
            {
                var users = from userinfo in context.tblUserDetalis
                            select new userinfo()
                                {
                                    User = userinfo.Username,
                                };
                list = users.ToArray();
            }
            return list;

        }    


  public class userinfo
        {
            public string User { get; set; }
        }



From This Code i am getting this API url: http://localhost:58000/api/Login/get123

Now I am trying to use this API in this HTML page:

XML
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="styles/kendo.common.min.css" rel="stylesheet" />
    <link href="styles/kendo.default.min.css" rel="stylesheet" />
    <script src="js/jquery.min.js"></script>
    <script src="js/kendo.all.min.js"></script>
</head>
<body>
    <div id="example" class="k-content">

    <div class="demo-section">
        <div id="listView"></div>
        <div id="pager" class="k-pager-wrap"></div>
    </div>

    <script type="text/x-kendo-template" id="xyz">
        <div class="product">
            <h3>#:User#</h3>
        </div>
    </script>

    <script>
        $(function() {
            var dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "http://localhost:58000/api/Login/get123",
                        dataType: "jsonp"
                    }
                },
                pageSize: 2
            });

            $("#pager").kendoPager({
                dataSource: dataSource
            });

            $("#listView").kendoListView({
                dataSource: dataSource,
                template: kendo.template($("#xyz").html())
            });
        });
    </script>

    <style scoped>
        .demo-section {
            padding: 30px;
            width: 577px;
        }
        #listView {
            padding: 10px;
            margin-bottom: -1px;
            min-width: 555px;
            min-height: 510px;
        }
        .product {
            float: left;
            position: relative;
            width: 111px;
            height: 170px;
            margin: 0;
            padding: 0;
        }
        .product img {
            width: 110px;
            height: 110px;
        }
        .product h3 {
            margin: 0;
            padding: 3px 5px 0 0;
            max-width: 96px;
            overflow: hidden;
            line-height: 1.1em;
            font-size: .9em;
            font-weight: normal;
            text-transform: uppercase;
            color: #999;
        }
        .product p {
            visibility: hidden;
        }
        .product:hover p {
            visibility: visible;
            position: absolute;
            width: 110px;
            height: 110px;
            top: 0;
            margin: 0;
            padding: 0;
            line-height: 110px;
            vertical-align: middle;
            text-align: center;
            color: #fff;
            background-color: rgba(0,0,0,0.75);
            transition: background .2s linear, color .2s linear;
            -moz-transition: background .2s linear, color .2s linear;
            -webkit-transition: background .2s linear, color .2s linear;
            -o-transition: background .2s linear, color .2s linear;
        }
        .k-listview:after {
            content: ".";
            display: block;
            height: 0;
            clear: both;
            visibility: hidden;
        }
    </style>
</div>

</body>
</html>



After doing all these i am able to see json data in firebugg in NET tab.
I have also checked data by calling API in browser and its coming properly.

See these result:

[{"User":"admin"},{"User":"nithya"},{"User":"piyush"},{"User":"govind"},{"User":"shiva"}]

help me to solve this issue i am facing from long time but not getting any solution.
Posted
Updated 12-Nov-13 18:34pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900