title: Fetch TagsInput from DB and Display on View in MVC
body: <p>I am having a problem fetching data from DB and displaying them on View in Edit. Assuming I have multiple tags in DB, I cannot fetch it on View.</p>
  <p><strong>Edit Controller //GET</strong></p>
  <pre><code>public ActionResult Edit(int? id)
           {
               if (id == null)
               {
                   return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
               }
               NotesInList notesInList = db.NotesInLists.Find(id);
               var tags = db.Tags.Where(x =&gt; x.Note_Id == id).FirstOrDefault();
                  
               if (notesInList == null)
               {
                   return HttpNotFound();
               }
               NoteTagViewModel NTVM = new NoteTagViewModel()
               {
                   Notes = notesInList,
                   TagsList = tags.ToString()
               };
               return View(NTVM);
           }
  </code></pre>
  <p><strong>Notes Model</strong></p>
  <pre><code>public class NotesInList
       {
           [Key]
           public int NoteId { get; set; }
      
           [Required]
           [Display(Name = &quot;Note Name&quot;)]
           public string NoteName { get; set; }
      
           [DataType(DataType.Date)]
           [Display(Name = &quot;Creation Date&quot;)]
           public DateTime? CreationDate { get; set; }
      
           [DataType(DataType.Date)]
           [Display(Name = &quot;Last Updated&quot;)]
           public DateTime? UpdateDate { get; set; }
      
           public string customFile { get; set; }
      
           [Display(Name = &quot;Enter Note Content&quot;)]
           public string TextDescription { get; set; }
      
           public List&lt;Tags&gt; Tags { get; set; }
      
           public Lists List { get; set; }
      
           public int ListId { get; set; }
       }
  </code></pre>
  <p><strong>Notes View Model</strong></p>
  <pre><code>public class NoteTagViewModel
       {
           [Key]
           public int NoteId { get; set; }
      
           [Required]
           [Display(Name = &quot;Note Name&quot;)]
           public string NoteName { get; set; }
      
           [DataType(DataType.Date)]
           [Display(Name = &quot;Creation Date&quot;)]
           public DateTime? CreationDate { get; set; }
      
           [DataType(DataType.Date)]
           [Display(Name = &quot;Last Updated&quot;)]
           public DateTime? UpdateDate { get; set; }
      
           public string customFile { get; set; }
      
           [Display(Name = &quot;Enter Note Content&quot;)]
           public string TextDescription { get; set; }
      
           //multiple tags
           public string TagsList { get; set; }
      
           public Lists List { get; set; }
      
           public int ListId { get; set; }
      
           public List&lt;Tags&gt; AllTags { get; set; }
      
           public NotesInList Notes { get; set; }
      
       }
  </code></pre>
  <p><strong>Edit View</strong></p>
  <pre><code>@model NoteBlocks.Models.NoteTagViewModel
  
  @{
  ViewBag.Title = &quot;Edit&quot;;
  }
  
  &lt;h2&gt;Edit&lt;/h2&gt;
  
  @using (Html.BeginForm(&quot;Edit&quot;, &quot;NotesInLists&quot;, FormMethod.Post, new { @enctype = &quot;multipart/form-data&quot; }))
  {
  @Html.AntiForgeryToken()
  
  &lt;div class=&quot;form-horizontal&quot;&gt;
  &lt;h4&gt;NotesInList&lt;/h4&gt;
  &lt;hr /&gt;
  @Html.ValidationSummary(true, &quot;&quot;, new { @class = &quot;text-danger&quot; })
  @Html.HiddenFor(model =&gt; model.NoteId)
  &lt;div class=&quot;form-group&quot;&gt;
       @Html.LabelFor(model =&gt; model.Notes.NoteName, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
       &lt;div class=&quot;col-md-10&quot;&gt;
           @Html.EditorFor(model =&gt; model.Notes.NoteName, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
           @Html.ValidationMessageFor(model =&gt; model.Notes.NoteName, &quot;&quot;, new { @class = &quot;text-danger&quot; })
       &lt;/div&gt;
   &lt;/div&gt;
   @if (Model.TextDescription == null &amp;&amp; Model.customFile != null)
   {
       &lt;div class=&quot;form-group&quot;&gt;
           @Html.Label(&quot;File Upload&quot;, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
           &lt;div class=&quot;col-md-10&quot;&gt;
               &lt;input type=&quot;file&quot; name=&quot;file&quot; class=&quot;form-control&quot; /&gt;
           &lt;/div&gt;
       &lt;/div&gt;
   }
   else
   {
       &lt;div class=&quot;form-group&quot;&gt;
           @Html.LabelFor(model =&gt; model.Notes.TextDescription, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
           &lt;div class=&quot;col-md-10&quot;&gt;
               @Html.TextAreaFor(model =&gt; model.Notes.TextDescription, new { @class = &quot;form-control&quot;, @cols = &quot;50&quot;, @rows = &quot;12&quot;, id = &quot;TextDescription&quot;, name = &quot;TextDescription&quot; })
               @Html.ValidationMessageFor(model =&gt; model.Notes.TextDescription, &quot;&quot;, new { @class = &quot;text-danger&quot; })
           &lt;/div&gt;
       &lt;/div&gt;
   }
   &lt;div class=&quot;form-group&quot;&gt;
       @Html.Label(&quot;Tags&quot;, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
       &lt;div class=&quot;col-md-10&quot;&gt;
             
           &lt;input type=&quot;text&quot; id=&quot;tagsfield&quot; name=&quot;tagsfield&quot; class=form-control data-role=&quot;tagsinput&quot; /&gt;
           &lt;input type=&quot;hidden&quot; name=&quot;TagsList&quot; id=&quot;TagsList&quot; /&gt;
       &lt;/div&gt;
   &lt;/div&gt;
   &lt;div class=&quot;form-group&quot;&gt;
       &lt;div class=&quot;col-md-offset-2 col-md-10&quot;&gt;
           &lt;input type=&quot;submit&quot; value=&quot;Save&quot; class=&quot;btn btn-default&quot; /&gt;
       &lt;/div&gt;
   &lt;/div&gt;
  &lt;/div&gt;
  }
  
  &lt;div&gt;
  @Html.ActionLink(&quot;Back to List&quot;, &quot;Index&quot;)
  &lt;/div&gt;
  
  @section scripts
  {
  &lt;script&gt;
  
       $(document.body).on('focusout', '.bootstrap-tagsinput input', () =&gt; {
       let array = $('#tagsField').tagsinput('items');
       $(&quot;#TagsList&quot;).val(array);
       })
   &lt;/script&gt;    
  }
  </code></pre>
  <p>I am not using JSON but for now want to handle it using Jquery. Please assist. I can see Text Description (if there is any) and Note Name (if there is any) in the textbox but not tags.</p>