.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

MVC - Return Array Json

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :ASP.Net
  function SaveDataToArray1(VungNguyenLieu, DienTich,LoaiGiong,
                                 SanLuong, TGXuongGiong, TGThuHoach) 
            var arr = new Array(arrData.length,
                                VungNguyenLieu, DienTich,LoaiGiong,
                                 SanLuong, TGXuongGiong, TGThuHoach);

        function ReloadGrid1() {
            $('#tbNoiDung tbody').html("");
            for (i = 0; i < arrData1.length; i++) {
                var tbRow = "<tr>";
                tbRow += "<td align=\"center\">" + (i + 1) + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][1] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][2] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][3] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][4] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][5] + "</td>";
                tbRow += "<td align=\"center\"

View Complete Post

More Related Resource Links

IE 8 partially cut of my JSON data return from WCF service

Hi All, I am not so sure here is the right place to post my issue. I am using ExtJS treepanel and ajax call to wcf webservice and return JSON array. My service return array. If array count is less than 2, then IE partially cut of my JSON data return from WCF service. But FireFox is working fine with same JSON format string. Very interesting thing is that I try to debug with Fildder. so I have to put "." dot in my url "http://localhost{.}:1234/ then It is working fine.   I am testing with IE8. Here is the JSON format return from FF and FireBug. {"result":[{"href":"..\/EMP\/EmployeeSearch.aspx","iconCls":"","id":"8c362443-7bb3-427e-910c-87b391c6abf5","leaf":true,"text":"Employees"}]} Here is the corrupted JSON string retrun from IE using developer tool. {"result":[{"href":"..\/EMP\/E" [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "GetSiteMap", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] [return: MessageParameter(Name = "result")] List<TreeView> GetSiteMap(string node);

How to use return JSON object from web service as a declared Type?

Hi, I just hit the following issue: I am calling a web service that returns a serialized JSON object let's say: __type, FirstName, LastName (.net object Person with properties FirstName and LastName). __type's value is Test.Person I have created a JS object using Type.registerNameSpace/registerClass called Demo.Person and it is registered on the page using the ScriptManager. Everything is working fine; I am able to get data from the server on the call back. Is it possible to make the returned object from the web service be an instance of the declared JavaScript Demo.Person class? The idea would be to call a method like result.getFullName() on the client side without having to copy all the properties. This is just a simple scenario for more complex objects.   Thanks,   Teo

how to query return all data in Array Object ,Collection Object

how to query return all data in Array Object ,Hash Table ,And DataTable dataRowSelect * From Doc a

Make my WCF service return json

Iam trying to make my wcf serivce method to return JASON-object, but it dosen't work, when I open in a webbrowser it shows xml. How can I make this method to return json.I have inserted [WebGet(ResponseFormat = WebMessageFormat.Json)],,,, but it didn't help[WebGet(ResponseFormat = WebMessageFormat.Json)] protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems() { // TODO: Change the sample implementation here if (items.Count == 0) { items.Add("A", new SampleItem() { Value = "A" }); items.Add("B", new SampleItem() { Value = "B" }); items.Add("C", new SampleItem() { Value = "C" }); } return this.items; }[WebGet(ResponseFormat = WebMessageFormat.Json)]         protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems()         {             // TODO: Change the sample implementation here             if (items.Count == 0)             {                 items.Add("A", new SampleItem() { Value = "A" });  &nb

Return an array to to jquery


Here's the problem I'm using the Jquery.ajax to call the [WebMethod].  I want to return some sort of array that I can use on the ajax side.  Are there any examples in doing this???  In addition can I return DataSets?



url: "Default.aspx/SeedCalendar",
data: "{'month': '" + month + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",

success: function(msg) {
$("#Result").text(msg[0]);  //first element in the array
error: function(e){ 
alert("error:" + e); 



public static string[] SeedCalendar(string month) 

string[] tseed = { "one", "two", "three" }; 

return tseed; 




What would make array.length return an incorrect number?


[sub-titled: array.length is working correctly, but Nick has almost certainly done something stupid.] 

This is probably obvious, but has got me mystified.  I have an array which is being created like this:

var TempPoints = $get('<%=PointList.ClientID%>').value;
PointsList = eval(TempPoints);

The field coming in from the server is formatted like this:

[[1,2], [3,4], [5,6], ......... [99, 100]]

So, after the eval has done its work, PointsList is an array of objects, each of which is an array containing two numbers.  If I then do a PointsList.length, I would expect to see the number of elements in the array.  I then of course need to remember that the array is zero based and that the last element is (PointsList.length - 1).  Well, so I would have thought!

In fact, the length seems to be reporting one more than it should, so the last element is actually (PointsList.length - 2).

That is borne out by what I can see in the Visual Studio debugger:

Visual Studio Screenshot

As you can see there, the array has elements 0 through 138 - but the length is reported as 140.

What am I missing?



Sending JSON Array to an ASP.NET MVC Action Method Argument


 <input type = "submit" onclick = "savePayment()"  value = "Test"/>

    <script type="text/javascript">
        function savePayment() {
            //Creating some test data
            var lineItems = new Object();
            lineItems.Entrys = new Array();
            lineItems.Entrys[0] = new Object({ Name: "Dung", Age: "21"});
            lineItems.Entrys[1] = new Object({ Name: "An", Age: "25" });

            //Posting them to server with ajax
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                url: '<%=Url.Action("TestArray", "Json") %>',
                dataType: 'json',
                data: $.toJSON(lineItems),
                success: function (result) {
                    if (result) {
                    else {

Deserializing a JSON array of mixed types



I'm having trouble deserializing a JSON array of mixed types using the DataContractJsonSerializer class. I've spent a bunch of time looking for a solution to no avail, so I thought I'd go ahead and ask here.

Basically, I am getting a JSON string like the one below. I'd like to get the array to deserialize into an List where position 0 has an Int32, position 1 has a String, and position 2 has an instance of my custom class.

"Mr. Smith",
"name":"main street",

.net 2010 REST WCF - json does not return the root List type



I am using the .net 2010 WCF Rest Service Application template to create my services.

The service needs to support two return format - xml and json which 2010 easily handles by changing the Accept value in the header info.

I have the following class structure

   public class ri
        public string nm { get; set; }

        public string nval { get; set; }

        public string cnt { get; set; }

    public class r
        public string val { get; set; }

        public string nm { get; set; }

        public List<ri> ri { get; set; }

   public class refinements
        public List<r> refs { get; set; }

   public class GetRefinementsSvc
        [WebGet(UriTemplate = "")]
        public refinements GetCollection

json array


i am new to json array... i cant understand one bit of this concept

i am pasting a code here. can any1  explain me this code

if (Request.QueryString["Tab"] == "Overview")
                sReturnVal = "{\"array_list\":{\"list\":[";
                sReturnVal += "{\"Source\":'" + Request.QueryString["Tab"] + "'}]";
                string strVal = "";

How to return a generic list in json format


Hi how would i go about returning a generic list in json format, can anyone point me to any good examples. Thanks

How to return serialized JSON object from WCF



I am able to return the JSON string from the wcf. But i want to return the JSON object from wcf.

Is is possible to return the JSON object from the wcf? If yes , then how?


Thanks in advance..... 

Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

ListView DataPager with SQL-Statements that already return only paged data.



As far as I understand the ListView-Control and the DataPager-Control, they work like this: The ListView gets its datarows from its data source, then the DataPager causes the ListView to display only a subset of those rows.

So what, when I want to use custom databinding for the ListView, that *already* gets the certain subset from SQL-Server (for better performance). Can I and how can I use the DataPager then?

Thanx, S.

how to get an array of all the asp.net textbox control inside create user wizard control?



How can I get all the textboxes inside a create user wizard control using getElementsByTagName().

Below is my JQuery code:

<script type="text/javascript">
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                window.onload = function() {

        function prepareInputsForHints() {
            var inputs = document.getElementsByTagName("asp:TextBox");
            for (var i = 0; i < inputs.length; i++) {
                inputs[i].onfocus = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                inputs[i].onblur = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "none";



<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

How to cast integer values as an array of enum values?


Hello all!

I'm working with VS2010 Beta2, ASP.NET and Dynamic Data. I'm using VB but will certainly be happy to receive a C# example if necessary. Laughing

I used a few of Steve's examples (Writing Attributes and Extension Methods for Dynamic Data and Dynamic Data - Hiding Columns in selected PageTemplates) to create a custom property attribute to be applied to a dynamic data column and want it to accept an array of enum values (each value will represent a dynamic data page template where this column should not be displayed).  My new attribute works fine when I hardcode it like this, meaning the HideColumnIn attribute is properly populated with the array of enum values:

<HideColumnIn(PageTemplate.List, PageTemplate.Edit)> _
Public Property My_DD_Column As Object


However, I want to store the values to be used for the HideColumnIn in the DB as integer values that correspond to the

Need Syntax To Make Results of LINQ Union Return Non-Generic Type



I have the below SQL which works just fine:

SELECT     Message, CreateDate, AccountId, AlertTypeId
FROM       dbo.Alerts
SELECT     TOP (100) PERCENT Status, CreateDate, AccountId,
                          (SELECT     10 AS Expr1) AS AlertTypeId
FROM         dbo.StatusUpdates
WHERE AccountId = PassedInParameter

I have been going about trying to convert the above into a LINQ method and am having problems with return types.
As the above SQL illustrates, I am querying two distinct LINQ tables - Alerts and StatusUpdates -
and then attempting to perform a Union on them. In order to do the union in LINQ, I have to have agreeing types. So, I
am using "var" to make the results of "alerts" and "updates" generic before the union.  

public IList GetStatusUpdatesAsAlertsByAccountId<T>(Int32 accountId)
            using (WorkbookDataContext dc = _conn.GetCont

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend