views:

48

answers:

1

how would I return a list of string in a json result in C# asp.net MVC?

I have this controller

  public JsonResult AutoCompletePart(string id)
    {
        AutoCompleteService srv = new AutoCompleteService();
        string[] parts = srv.AutoCompleteItemMaster(id);

        //how do i return parts as JSON?

    }

Thanks

+6  A: 

Like this:

return Json(parts, JsonRequestBehavior.AllowGet);

This will return a simple Javascript string array.
If you want to return specific format, please provide more detail.

SLaks
I love how easy this is in ASP.NET MVC.
Matt Peterson
NICE! I was making it harder than it was! Thanks!
twal