3

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.

Daniel Eisenreich
  • 1,353
  • 3
  • 16
  • 32
  • 1
    Share what have you tried so far. – Kumar_Vikas May 17 '17 at 11:09
  • 1
    You can't do this with razer. I'd recommend checking out knockout.js library. As for now, perhaps try loading the dropdown data from a hidden field or load it with ajax. – Anton Toshik May 17 '17 at 11:51
  • 1
    @AntonToshik I prefer to stay with ASP.NET Core MVC, because adding such a huge JS-Framework will blow up the time limit. Currently im working on this approach: [Click here](http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/). – Daniel Eisenreich May 17 '17 at 13:12
  • http://stackoverflow.com/questions/43794893/how-to-copy-table-row-with-dropdownlist-in-with-jquery/43796337#43796337 – Ashiquzzaman May 17 '17 at 13:47
  • @Ashiquzzaman First, thanks for your reply. This approach will work, but isn't that clean way what I'm looking for. I found another approach what im actually trying on. If u're interested in [Check this](https://github.com/saad749/BeginCollectionItemCore) – Daniel Eisenreich May 17 '17 at 14:58

0 Answers0