ASP.NET Core MVC add/remove dynamic content

Viewed 1267

I'm currently developing a system which manages work times and analyze them. Therefore I need to add several Time-Stamps once and add/remove some input field dynamically.

The ViewModel looks like:

public class CreateWorkDayViewModel
{
    public DateTime Date { get; set; }
    public IEnumerable<CreateStampModel> Stamps { get; set; }
}

public class CreateStampModel
{
    public string ProjectId { get; set; }
    public DateTime From { get; set; }
    public DateTime To { get; set; }
}

How to do this with the razer syntax including validation?

I'm developing with Visual Studio Version 15.2 and the latest stable MVC version.

EDIT (17.05.17):
What I've done so far:

I added a jQuery based mechanism to add/remove rows dynamically.
Click for the mechanism
My problem is, that in the part of where I'm adding the rows(at JS line 4) I can't use the razor syntax because this html code is inserted at runtime by jQuery.
I also tried it with the old way and used instead of asp-for name. This works for the post data, but to fill the project drop-down selection I need the data from the ViewModel and this is missing.

0 Answers
Related