asp.net mvc - How to pass List<string> model property to view javascript array variable? -
this question has answer here:
i have viewmodel property
public list<string> answers { get; set; }
how pass values of list array variable?
currently have javascript code in view, has error on answers array inside foreach loop.
the name answers not exists in current context.
<script type="text/javascript"> var answers = []; @foreach(string answer in model.answers) { var ans = @answer; answers.push(ans); } </script>
use json.net serializing json. use religiously ! think cleanest way json client. separate api call. retrofitted web api our server-rendered application don't need worry invoking json.net. return c# objects , web api converts them. (not new technology !) shouldn't doing in razor template.
wiki
Comments
Post a Comment