Hi,
Iam trying to pass data from my controller, and put it into the variable in JS script. I have done it before and it worked perfectly, thats why this one puzzles me even more.
Here is my code of the controller:
public ActionResult GetCategories()
{
var categories = categoryRepository.ListActiveCategories().ToList();
return View(categories);
}
And this is my JS code in the view:
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
var categories = JSON.parse('<%= Model %>');
</script>
And this is the output I get on my website in the browser:
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
var categories = JSON.parse('System.Collections.Generic.List`1[SklepOnline.Category]');
</script>
In chrome I also get an error "Uncaught SyntaxError: Unexpected token ILLEGAL". Any ideas what is wrong in this code? I am pretty sure it is the same I use for my other project and that one works just great so I really dont know what is wrong. Any help would be much appreciated.
Best Regards Bhaal275