Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Frederik T 220 posts 310 karma points
    Feb 12, 2013 @ 12:46
    Frederik T

    Contacting web services API from a razor script

    Ok so this is making me and my collegues scratching our heads.

    We have developed our own internal web services api to contact our databases, and thought it would be straightforward to use it with razor, and combine it with knockout js. Well, after a ton of trail and error, it still doesnt work, and we have somehow nailed it down to umbraco blocking the web service.

    I have searched around and either solutions we found doesnt work, or the information is inconsistent.

    This is our razor script:

    <script src="/Scripts/knockout-2.1.0.js"></script>
    <h1>Tilmed </h1>
    <p>Name: <strong data-bind="text: name"></strong></p>
    <p>Email: <strong data-bind="text: email"></strong></p>

    <p>Name: <input data-bind="value: name" /></p>
    <p>Email: <input data-bind="value: email" /></p>

    <script type="text/javascript">

        var ViewModel = function() { //Make the self as 'this' reference
            var self = this; //Declare observable which will be bind with UI
   = ko.observable("enter name");
   = ko.observable("enter email");


            function getMPerson() {

            // the url to the service
             url: "",
            // the format that the data should be in when
            // it is returned
             contentType: "json; charset=utf-8",
            // the function that executes when the server
            // responds to this ajax request successfully
            success: function (data) {
                // Update view model properties
            error: function (error) {
                alert("ERROR STATUS: " + error.status + "  STATUS TEXT: " + error.statusText);

        }; // end viewmodel definition
        ko.applyBindings(new ViewModel());

    Any suggestions? Some oversights or anything?

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    Feb 14, 2013 @ 00:54
    Bo Damgaard Mortensen

    Hi Frederik,

    What kind of service have you created? .asmx? svc? /base? Also, if you hit F12 in Google Chrome and go to the network tab, do you get any response when invoking your ajax call?

    All the best,


Please Sign in or register to post replies

Write your reply to: