0

I have an application I want to add tags input box

I used http://aehlke.github.io/tag-it/examples.html library

Controller Create Method:

        // GET: Posts/Create
    public ActionResult Create()
    {
        var Tags = db.MyTags.Select(t=>t.TagName).ToArray();

        ViewBag.ExistingTags = Tags;
        return View();
    }

View:

I have below script

<script>
    $(function(){
        //var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'go', 'lua'];
        var sampleTags = JSON.stringify(@ViewBag.ExistingTags);

</script>

how can I get the passed ExistingTags array as the sample code commented

1
  • Stephen you are incorrect reason Commented Apr 6, 2016 at 11:58

1 Answer 1

1

Use @Html.Raw() and Json.Encode() as shown :-

<script>
    $(function(){
        //var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'go', 'lua'];
        var sampleTags = @Html.Raw(Json.Encode(@ViewBag.ExistingTags));
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

@MehdiJalal..happy to help you..;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.