【问题标题】:MVC3 - How to modify action result to get multiple objects updateMVC3 - 如何修改操作结果以获取多个对象更新
【发布时间】:2011-07-12 19:49:10
【问题描述】:

当我从下拉列表中选择一个剧院并单击“添加电影”时,此代码将运行。

   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");
    }

生成的数据库条目是 Json 格式,如下所示..

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

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

     }

当我按照相同的工作流程向该影院添加第二部电影时。也就是说,选择一个影院,然后添加第二部电影的详细信息,我希望将第二部电影添加到同一文档中的第一部电影旁边,如下所示等等,以供将来的其他电影...

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

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

     }

如何更改我的操作结果代码以完成此功能..感谢您的帮助..

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-3 document-based


    【解决方案1】:

    我建议使用客户端模板框架。您可以使用的一个非常好的工具是 Steve Sanderson 的 KnockoutJS。见knokcout js

    【讨论】:

      猜你喜欢
      • 2011-08-23
      • 1970-01-01
      • 2022-01-07
      • 2020-08-15
      • 2011-12-18
      • 2012-03-22
      • 1970-01-01
      • 2017-06-30
      • 1970-01-01
      相关资源
      最近更新 更多