Try our conversational search powered by Generative AI!

Partialview error??

Vote:
 

Hi guys,

   i want to implement partial views in episerver,below code represent partial view.

Partial.cs:-

        namespace Partialviewtesting.Models.Pages
        {
            [ContentType(DisplayName = "Partial", GUID = "e87dba5c-37e3-49ad-a49e-e5d8211a2c59", Description = "")]
            public class Partial : PageData
           {

            /*[CultureSpecific]
               [Display(
               Name = "Main body",
               Description = "",
              GroupName = SystemTabNames.Content,
              Order = 1)]
              public virtual string MainBody { get; set; }*/
           }
       }

here i didn't create any properties in Partial.cs.

PartialController:-

                public class PartialController : PageController
                {

                      public ActionResult Index(Partial currentPage)
                      {
                        return View(currentPage);
                     }
                }

Partilaview i.e:Index.cshtml:-

           @model Partialviewtesting.Models.Pages.Partial
           

this is partial page

Now i want to call the partial view in my home page.

Home.cs:-

            namespace Partialviewtesting.Models.Pages
             {
                  [ContentType(DisplayName = "Home", GUID = "a1d73a46-383d-42c4-9439-a42c7b7a1ee9", Description = "")]
                  public class Home : PageData
                  { 

                      [CultureSpecific]
                      [Display(
                      Name = "Main body",
                      Description = "",
                      GroupName = SystemTabNames.Content,
                      Order = 1)]
                      public virtual string MainBody { get; set; }

                 }
            }

HomeController:-

                 namespace Partialviewtesting.Controllers
                  {
                     public class HomeController : PageController
                       {
                         public ActionResult Index(Home currentPage)
                           {

                              return View(currentPage);
                            }
                         }
                    }

Homeview i.e(Index.cshtml):-

                       @model Partialviewtesting.Models.Pages.Home
                       @Html.PropertyFor(p => p.MainBody)

                        This Is Home page

                                     

                             

                                     @{ Html.RenderAction("Index", "Partial");}                                 

                             

                         


     


   


Here i get the error like "Additional information: The routed data is of type 'Partialviewtesting.Models.Pages.Home' and the binding context 'currentPage' is null, cannot bind any value to type 'Partialviewtesting.Models.Pages.Partial'." if anyone working on partialview please let me help out of this.

Thanks,

Ramkee.G

#179796
Edited, Jun 22, 2017 8:02
Vote:
 

A better approach would be to create a block instead of the Partial page which can be dragged & dropped to ContetArea on the Start page.

Then you should use something like  @Html.PropertyFor(x => x.MyContentArea) to display blocks. 

#179798
Edited, Jun 22, 2017 9:43
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.