0

In function (data), data is receiving list of records. How can I retrieve all records from "data" and show it in /status/create view

function PassType() {

alert("pass function")

var formData = $("#sid").val();
    alert(formData);

    $.post("/Status/Create", { typeId: formData }, function (data) {
            document.write(data)
        }, "text");

};

3 Answers 3

1

Hi you can use below code to iterate the data received in JSON format:

var formData = $("#sid").val();
alert(formData);

$.post("/Status/Create", { typeId: formData }, function (data) {
        document.write(data);
        $.each(data, function(key, value){
            // Here you can iterate data one by one and process it.
        });
    }, "text");

};

Or

you can use jQuery template also. Please refer to the jquery template from here.

Sign up to request clarification or add additional context in comments.

Comments

0

You should pass data from controller as structured data that is good one is JSON, then you can access each row with $.each and properties as item.[property1] for example

$.each(data, function(index, element) {
              var propertyName = element.name;
            });

Useful links: http://api.jquery.com/jquery.post/ AND http://api.jquery.com/jquery.post/

Hope this help.

Comments

0

If you want to render that ajax response as part of your document, you will need to do it on the client side. This means either doing some basic manual templating (using string replacements) or you'll need to use a client side templating system.

There does appear to be something that let's you use RAZOR templates on the client: http://mvccontrolstoolkit.codeplex.com/wikipage?title=Client-Side%20Templates.

Otherwise there are plenty of client side templating systems you can use: mustache, icanhaz, etc. There is one that is tied to jquery as well.

This is seems to be a nice review of the leading ones:

http://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more

Depending on your page structure you may have to do some dom manipulation to render your templates.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.