how to ingore comma when returning json mvc
- by Darcy
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?