0

I return multiple json objects but i don't know how to return that objects. I want to get returned json objects and send them to ajax request. This is my ActionResult:

public ActionResult AutoCompleteEventName(string eventName)
        {
            Event ev = new Event();
            ev.Name = eventName;
            var searchEvent = EventService.Instance.Search(ev);
            var totalCount = EventService.Instance.SearchCount(ev);           
        }
0

3 Answers 3

1

If you want to send object's list, you can do it with this way:

var yourObjectList = EventService.Instance.LoadSomeEvents();

List<object> objectList = new List<object>();

foreach (var event in yourObjectList)
{
     objectList.Add(new
                   {
                        id = event.Id,
                        name = event.Name,
                    });
}

return Json(objectList, JsonRequestBehavior.AllowGet);
Sign up to request clarification or add additional context in comments.

Comments

1
return Json(new { searchEvent = searchEvent , totalCount  = totalCount }, JsonRequestBehavior.AllowGet)

Comments

1

in controller return result as below

 var returnField = new { searchEvent  = "searchEvent", totalCount = totalCount.ToString() };
return Json(returnField, JsonRequestBehavior.AllowGet);

in Ajax Request

 success: function (data) {
var searchEvent  = data.searchEvent;
var totalCount =data.totalCount 
}

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.