I am trying to find the cleanest way to pass a object (recordset list) from the MVC 4 Controller to the View as a Json object.
Controller:
var mem = BLL.Presenters.Account.GetAll().ToList();
return View(mem);
View:
<script type="text/javascript">
// Load data from view
var globalData = @(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model)))
</script>
The javascript object has globalData which contains JSON.
Looking at the View, I am calling the Newtonsoft.Json.JsonConvert.SerializeObject, which I rather have in the Controller.
When I move the JsonConvert.SerializeObject to the Contoller:
var mem = BLL.Presenters.Account.GetAll().ToList();
var json = Newtonsoft.Json.JsonConvert.SerializeObject(mem);
return View(json);
I get the error: Illegal characters in path.
How can I pass along a json object (already Serialize) from the Controller to the View using Newtonsoft.Json ?