PartialView累积添加问题

时间:2013-06-19 08:29:03

标签: asp.net-mvc razor partial-views actionresult

我想制作一个模块化的网站。一切顺利但我在累积添加模块时遇到了问题。我想动态加载内容如下:

联系页面:

  1. Content.cshtml:Lorem ipsum dolor
  2. Contact.cshtml
  3. Content.cshtml:地址:第比利斯/格鲁吉亚
  4. 但是只加载第一个内容,如下所示

    1. Content.cshtml:Lorem ipsum dolor
    2. Contact.cshtml
    3. Content.cshtml:Lorem ipsum dolor
    4. 我该如何解决这个问题?

      tblModule

      +---------+-------------------------+
      | ModulId |  PhysicalPath           |
      +---------+-------------------------+
      |    1    |  /Content.cshtml        |
      +---------+-------------------------+
      |    2    |  /Contact.cshtml        |
      +---------+-------------------------+
      

      的tblpage

      +---------+-------------------------+
      | PageId  |  Page                   |
      +---------+-------------------------+
      |    1    |  About                  |
      +---------+-------------------------+
      |    2    |  Contact                |
      +---------+-------------------------+
      

      tblContent

      +------------+----------------------------+
      | ContentId  |  Content                   |
      +------------+----------------------------+
      |    1       |  Lorem ipsun dolor...      |
      +------------+----------------------------+
      |    2       |  Adress : Tbilisi/Georgia  |
      +------------+----------------------------+
      

      tblPageModules

      +---------+-------------+-------------+
      | PageId  |  ModuleId   |  OrderId    |
      +---------+-------------+-------------+
      |    2    |      1      |      1      |
      +---------+-------------+-------------+
      |    2    |      2      |      2      |
      +---------+-------------+-------------+
      |    2    |      1      |      3      |
      +---------+-------------+-------------+ 
      

      ModuleRepository.cs

      public class ModuleRepository
      {
          public IEnumerable<Modules> Module { get; set; }
          public IEnumerable<PageModules> PageModule { get; set; }
          public ContentBlock Content { get; set; }
      }
      

      控制器

      public ActionResult Page()
      {
          int PageId = default(int);
          if (RouteData.Values["id"] != null)
          {
              PageId = int.Parse(RouteData.Values["id"].ToString());
          }
      
          using (ContentModel db = new ContentModel())
          {
              var module = from n in db.PageModule
                           join m in db.Module on n.ModuleId equals m.ModuleId
                           where n.PageId == PageId
                           orderby n.OrderId
                           select m;
      
              var model = new ModuleRepository
              {
                  Module = ViewName.ToList(),
                  Content = db.ContentBlock.Where(n => n.PageId == PageId).First()
              };
      
              return View(model);
          }
      }
      

      Page.cshtml

      @model ModuleRepository
      @foreach (var modul in Model.Module)
      {
          @Html.Partial(@modul.PhysicalPath, Model)
      }
      

      Content.cshtml

      @model ModuleRepository
      @Html.Raw(@Model.Content.Content)
      

0 个答案:

没有答案