In my project users can add a entry in the database of a video they want to store. The video is supposed to have multiple tags (optional) go with it. What is a good way to let users enter dynamically multiple tags?
I have created three models, Video, Tag and VideoTags, which holds the m2m relationship of the tags for each video.
Video
public class Video: BaseModel
{
public string Name { get; set; }
public string OriginUrl { get; set; }
public string Description { get; set; }
public string FileLocationIcon { get; set; }
public ICollection<VideoTags> VideoTags { get; set; }
}
Tag
public class Tag: BaseModel
{
public string TagName { get; set; }
public ICollection<VideoTags> VideoTags { get; set; }
}
VideoTags
public class VideoTags
{
public string VideoId { get; set; }
public Video Video { get; set; }
public string TagId { get; set; }
public Tag Tag { get; set; }
}
My html (Create.cshtml)
<div class="col-md-4">
<form asp-action="Create" enctype="multipart/form-data" method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="OriginalUrl" class="control-label"></label>
<input asp-for="OriginalUrl" class="form-control" />
<span asp-validation-for="OriginalUrl" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description" class="control-label"></label>
<textarea asp-for="Description" class="form-control"> </textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Icon" class="control-label"></label>
<input type="file" asp-for="Icon" class="form-control" accept="image/x-png,image/gif,image/jpeg" />
<span asp-validation-for="Icon" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
Now, my question is how can I properly implement this on my html form where the user provides the other details of the Video entry?
I think it will involve JQuery
, but I don't really know how to proceed. Users are supposed to add these tags, so I want them to be able to add input fields if needed, and then on Submit to the backend, my Controller
will take that input and turn it into a IEnumerable
or List
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…