title: With Asp.Net Mvc programmatically define section name in content page
body: <p>I'm not talking about the RenderSection and my question is not related direcly with layout page.</p>
  
  <p>First of all i want to tell you what im trying to do. I have a</p>
  
  <pre><code>public class Module
  {
      public int Id { get; set; }
      public string Title { get; set; }
      public string Content { get; set; }
      public int Ordering { get; set; }
      public string Position { get; set; }
      public bool Published { get; set; }
      public string ModulePath { get; set; }
      public bool ShowTitle { get; set; }
  }
  </code></pre>
  
  <p>table named Module. Modules are like Widgets. Please pay attention to the Position and ModulePath fields.</p>
  
  <p>Positions are like ContentPlaceHolder defined in Layout page. In Mvc i define position like below.</p>
  
  <pre><code>RenderSection("PositionName", required:false)
  </code></pre>
  
  <p>ModulePath field holds the PartialView's location. They will be rendered in layout.</p>
  
  <p>Problem starts here. How to do this programmatically.</p>
  
  <p>Normally we use; </p>
  
  <pre><code>@section PositionName
  {
     @html.Partial(...)
  }
  </code></pre>
  
  <p>to define a section in content page.</p>
  
  <p>In Asp.net WebForms it is very easy to do.</p>
  
  <pre><code>ContentPlaceHolder.FindControl(PositionName).Controls.Add(..)
  </code></pre>
  
  <p><strong>I need to specify section names programmatically, which is in a content page</strong></p>
  
  <p>Actually i need something like this;</p>
  
  <pre><code>foreach(var item in Model.Modules)
  {
     this.AddSection(item.Position, item.ModulePath, item.Ordering)
  }
  </code></pre>
  
  <p>Manual way</p>
  
  <pre><code>@section PositionName
  {
      @html.Partial("~/Views/Shared/AModule.cshtml")
      @html.Partial("~/Views/Shared/AnotherModule.cshtml")
      @html.Partial("~/Views/Shared/AnotherModule.cshtml")
  }
  </code></pre>
  
  <p>I tried;</p>
  
  <pre><code>@section @SectionName
  {
     ...
  }
  </code></pre>
  
  <p>ofcource failed. </p>
  
  <p>So its very good idea to dynamically place PartialViews anywhere of page which their positions setted at administration panel. Thats what im trying to do.</p>