how to ingore comma when returning json mvc

Posted by Darcy on Stack Overflow See other posts from Stack Overflow or by Darcy
Published on 2010-04-01T18:44:45Z Indexed on 2010/04/01 23:23 UTC
Read the original article Hit count: 353

Filed under:
|
|
|

Hi all,

I'm returning JSON from my controller to my view in order to populate a jquery autocomplete textbox in MVC. The problem is, some of my data contains commas, and therefore is split by the autocomplete helper.

Heres my code.

Controller:

    public ActionResult GetData()
    {
        var data = repository.GetData();

        return Json(data);
    }

View (script):

    $.post("../MyController/GetData",

        function(data) {
        var evalData = eval(data) + ""; //formats the text

        $("#Data").autocomplete(evalData.split(","),
        {
            max: 500,
            matchContains: true
        });
    });

As you can see, I am using the jquery .split helper to split the returned Json. Should I be using regex or should I go with a completely different approach?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about jQuery