asp.net-mvcrazorumbracoarticulate

How to divide a Certain Model into two parts in Razor View?


I am using Articulate plugin in Umbraco for Blog Style and I need to show something default inside every Articulate Post. Here is what is happening now.

<section class="post-content">
   @Model.Body
</section>

And I need to do something below

<section class="post-content">
   @Model.Body.part1
   "Something Very Important"
   @Model.Body.part2
</section>

Thanks in advance.


Solution

  • Create two partial views and pass the same model to both. On each view just render the part you want.

    <section class="post-content">
       @* the model will be passed to the partial view *@
       @Html.Partial("~/Views/Partial/PartialView1.cshtml"); 
    
       <p>Something very important here</p>
    
       @Html.Partial("~/Views/Partial/PartialView2.cshtml");
    </section>
    

    Then your partial views would be something like:

    PartialView1.cshtml

    <div>
       @Model.Body.part1
    </div>
    

    PartialView2.cshtml

    <div>
       @Model.Body.part2
    </div>
    

    You don't really need the <div> but you get the point, right?