0

Currently am making a jQuery ajax call to MVC method and sending data from Controller in the below format:

["UserInfo ID","User ID"]

Controller code:

 var autoSuggestlist;
 ........
 .
 return Json(autoSuggestlist, JsonRequestBehavior.AllowGet);

Now I want to add another different data like:

[ {"editable":true,"edittype":"integer","index":"userInfoId" ]

How I can send these 2 different datas in Controller to jQuery Ajax

In the below code

$.ajax(
 {
 type: "GET",
 url: "/Home/GetColumnNamesForGrid",
 data: "",
 dataType: "json",
 async: false,
 success: function (result) {

result should get me both the above JSON data. How do I need to modify my Controller Code. Please assist

Thanks

Jason Aller
3,66028 gold badges42 silver badges40 bronze badges
asked Mar 14, 2013 at 12:01

1 Answer 1

1

Not sure exactly what you mean, but if you want to sent an object with properties from the controller, you can do this:

return Json(new { editable = true, edittype = "integer", index = "userInfoId" }, JsonRequestBehavior.AllowGet);

Then from javascript, your result object can be used as follows:

var editable = result.editable;//will be true

If you are actually wanting to send both data types back at the same time, then create a wrapper object like so:

var myObject = new { editable = true, edittype = "integer", index = "userInfoId" };
var myArray = autoSuggestlist;
return Json(new { @myObject = myObject, @myArray = myArray}, JsonRequestBehavior.AllowGet);

Then use in javascript like this:

var myObject = result.myObject;
var editable = myObject.editable;//will be true
var myArray = result.myArray;
var firstItem = myArray[0];//will be "UserInfo ID"
answered Mar 14, 2013 at 12:08

2 Comments

i want to send 2 classes at the same time. Is it possible ?
yes you can. but you need to create ViewModel which hold the Two class data.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.