0

Am working in MVC. In my controller am creating a list

 public class GridColModelLst
    {
        List<GridColModel> _items = new List<GridColModel>();

        public List<GridColModel> items
        {
            get { return _items; }
            set { _items = value; }
        }
    }


    public class GridColModel
        {
            public string name { get; set; }
            public int? width { get; set; }
    }

And passing this list as JSON which works fine and my JSON is below

[{ name: 'Humidity', width: 90}]

How do i make it like the below JSON To add a JSON Array inside a JSON object in C#

[{ name: 'Humidity', width: 90, searchoptions: { sopt: ['eq', 'ne'] } }]

Thanks

====================

update

In my controller am sending the list like

return Json(Colmodel, JsonRequestBehavior.AllowGet);

and am getting [{ name: 'Humidity', width: 90}] succesfully

What changes i need for the class to get a JSON like

[{ name: 'Humidity', width: 90, searchoptions: { sopt: ['eq', 'ne'] } }]

1 Answer 1

1

Try this:

 return Json(new { name = "Humidity", width = 90, searchoptions = new { sopt = new string[] { "eq,nq" } } }, JsonRequestBehavior.AllowGet);
Sign up to request clarification or add additional context in comments.

3 Comments

Am returning JSONRESULT using MVC Controller
Can you do return Json(some object)
Yes i did that n i got the josn object. My questoin is what change i need to make in C# to add Json array inside json object. See my 2nd JSON in my question

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.