Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 部分视图累积添加问题_Asp.net Mvc_Razor_Partial Views_Actionresult - Fatal编程技术网

Asp.net mvc 部分视图累积添加问题

Asp.net mvc 部分视图累积添加问题,asp.net-mvc,razor,partial-views,actionresult,Asp.net Mvc,Razor,Partial Views,Actionresult,我想建立一个模块化的网站。一切都很顺利,但我在累积添加模块时遇到了一个问题。我想动态加载内容,如下所示: 联系人页面: Content.cshtml:Lorem ipsum dolor Contact.cshtml Content.cshtml:地址:第比利斯/格鲁吉亚 但只正确加载第一个内容,如下所示 Content.cshtml:Lorem ipsum dolor Contact.cshtml Content.cshtml:Lorem ipsum dolor 我怎样才能解决这个问题 TBL模

我想建立一个模块化的网站。一切都很顺利,但我在累积添加模块时遇到了一个问题。我想动态加载内容,如下所示:

联系人页面:

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

  • Content.cshtml:Lorem ipsum dolor
  • Contact.cshtml
  • Content.cshtml:Lorem ipsum dolor
  • 我怎样才能解决这个问题

    TBL模块

    +---------+-------------------------+
    | ModulId |  PhysicalPath           |
    +---------+-------------------------+
    |    1    |  /Content.cshtml        |
    +---------+-------------------------+
    |    2    |  /Contact.cshtml        |
    +---------+-------------------------+
    
    +---------+-------------------------+
    | PageId  |  Page                   |
    +---------+-------------------------+
    |    1    |  About                  |
    +---------+-------------------------+
    |    2    |  Contact                |
    +---------+-------------------------+
    
    tblPage

    +---------+-------------------------+
    | ModulId |  PhysicalPath           |
    +---------+-------------------------+
    |    1    |  /Content.cshtml        |
    +---------+-------------------------+
    |    2    |  /Contact.cshtml        |
    +---------+-------------------------+
    
    +---------+-------------------------+
    | PageId  |  Page                   |
    +---------+-------------------------+
    |    1    |  About                  |
    +---------+-------------------------+
    |    2    |  Contact                |
    +---------+-------------------------+
    
    tbl内容

    +------------+----------------------------+
    | 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; }
    }
    
    Page.cshtml

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

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