MVC and jQuery data retrieval.

Posted by user337542 on Stack Overflow See other posts from Stack Overflow or by user337542
Published on 2010-05-10T17:58:43Z Indexed on 2010/05/10 18:14 UTC
Read the original article Hit count: 244

Filed under:
|
|
|
|

Hello, I am using mvc and jQuery and I am trying to display someone's profile with some additional institutions that the person belongs to. I am new to this but I've done something like this in ProfileControler:

public ActionResult Institutions(int id)
    {
       var inst = fr.getInstitutions(id);
        return Json(inst);
    }

getInstitutions(id) returns Institution objects(with Name, City, Post Code etc.) Then in a certain View I am trying to get the data with jQuery and display them as follows:

$(document).ready(function () {
        $.post("/Profile/Institutions", { id: <%= Model.Profile.userProfileID %> }, function (data) {
            $.each(data, function () {

                var new_div = $("<div>");

                var new_label = $("<label>");
                new_label.html(this.City);

                var new_input_b = $("<input>");
                new_input_b.attr("type", "button");

                new_div.append(new_label);
                new_div.append(new_input_b);

                $("#institutions").append(new_div);
            });
        });
    });

$("#institutions") is a div where i want to display all of the results. .post works correct for sure because certain institutions are retrieved from database, and passed to the view as Json result. But then I am affraid it wont itterate with .each.

Any help, coments or pointing in some direction would be much appriciated

© Stack Overflow or respective owner

Related posts about mvc

Related posts about JSON