1

When I select a theater from a drop down and click on 'add a movie', this code is run.

   public ActionResult Create(TheaterViewModel input)
    {
        var theater = new TheaterViewModel
          {  
              TheaterId = input.TheaterId,
              TheaterName = input.TheaterName,                

              MoviesForTheater = new List<Movie>
                {
                    new Movie 
                     {                             
                         Title = input.Movie.Title,                                                    
                         Category = input.Movie.Category 
                     }
                }
          };

        _repository.Add(theater);           
        _repository.Save();           
        return RedirectToAction("Index");
    }

The resulting database entry is in Json format and is as below..

    {
      "TheaterId": 12312,          
      "TheaterName": "AMC",

      "MoviesForTheater": [
         {
             "Title": "Shrek",          
             "Category": "G",
          }
         ],

     }

When I add a second movie to this theater following the same work flow.. that is, pick a theater and then add 2nd movie details, I want the second movie to be added next to first movie in the same document as follows and so on for additional movies in future...

 {
      "TheaterId": 12312,          
      "TheaterName": "AMC",

      "MoviesForTheater": [
         {
             "Title": "Shrek",          
             "Category": "G",
          },
          {
             "Title": "Shrek2",          
             "Category": "G",
          }
         ],

     }

How do I change my actionresult code to accomplish this feature..Thanks for your help..

ZVenue
  • 4,967
  • 16
  • 61
  • 92

1 Answers1

2

I recommend using a client side templating framework. A really good one you can use is KnockoutJS by Steve Sanderson. See knokcout js

Haacked
  • 58,045
  • 14
  • 90
  • 114