Cannot get my html input array for serialization in List <string> in Asp.Net mvc

I am trying to implement a tag system in my asp.net MVC project. When a user edits or adds a task, they can add any number of tags that they want before submitting. I use the Jquery Tagit plugin, so when the user adds a new tag, an input field is created that looks like this:

<input type="hidden" style="display:none;" value="tag1" name="Tags[]">

When the user clicks the submit button after adding several tags, the browser sends the following chain to the server (retrieved through the violinist):

IsNew=True&Id=2222&Title=Test+Title&Description=Test+Description&Tags%5B%5D=Tag1&Tags%5B%5D=blah&Tags%5B%5D=another-tag

Now my view model, in which I am serializing this data, has the following structure:

public class KnowledgeBaseTaskViewModel
{
    public int Id { get; set; }

    [Required(AllowEmptyStrings=false, ErrorMessage="Task title is required")]
    [StringLength(500)]
    public string Title { get; set; }

    [Required(AllowEmptyStrings=false, ErrorMessage="Task description is required")]
    [StringLength(500)]
    public string Description { get; set; }

    public List<string> Tags { get; set; }
    public bool IsNew { get; set; } // Needed to determine if we are inserting or not
}

Finally, my host action has the following signature:

    [HttpPost]
    public ActionResult EditTask(KnowledgeBaseTaskViewModel task)

, , - null. , , , . .

+1

All Articles