0

Hi guys i have a project that follows the 3 tier architecture, in my web application that uses mvc 4 i am trying to use knockout binding, but however my data is retrieve from my data tier but the UI is not been updated. Below are my code snippet

My Model that reside in my data tier which is a separate class library

public int SocialProfileId { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Url { get; set; }
public string ImgUrl { get; set; }

My View model in my web project var SocialViewModel = function () { var self = this;

self.Title = ko.observable("");

self.SocialLinks = ko.observableArray();

GetSocialLinks();

function GetSocialLinks() {
    $.ajax({
        type: "GET",
        url: "Ville/SocialLnk",
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function (data) {
            self.SocialLinks(data);
            alert(data[0]);
        },

        error: function (error) {
            alert(er.status + "<--and-->" + erro.statusText);
        }
    });
}
}

My view showing my binding

<ul class="bl-socialLink" data-bind="foreach: SocialLinks">
<li>
    <p data-bind="text: Title"></p>
    <a data-bind="attr: { title: Title, href: Url}" target="_blank">
        <img data-bind="attr: { alt: Title, src: ImgUrl }" />
    </a>
</li>

How do i make my UI display the information? Because i cant figure out why my view is not displaying the values. Thanks

1 Answer 1

1

Are you applying the bindings? I don't see it in your code sample

ko.applyBindings(SocialViewModel);

I'd also recommend looking over the troubleshooting strategies here

The "pre" example is super helpful:

<pre data-bind="text: ko.toJSON($data, null, 2)"></pre>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.