Try our conversational search powered by Generative AI!

The model item passed into the dictionary is of type 'Castle.Proxies.HelloWorldPageProxy', but this dictionary requires a model item of type 'DxcAlloy

Vote:
 

The model item passed into the dictionary is of type 'Castle.Proxies.HelloWorldPageProxy', but this dictionary requires a model item of type 'DxcAlloy.Models.ViewModels.IPageViewModel`1[DxcAlloy.Models.Pages.SitePageData]'.

i am trying to add a hello world page to alloy, but get he above error when i hit: http://localhost:60746/en/helloworld

Controllers/HelloWorldPageController.cs

namespace DxcAlloy.Controllers
{
    public class HelloWorldPageController:PageController<HelloWorldPage>
    {
        public ActionResult Index(HelloWorldPage currentPage)
        {
            return View(currentPage);
        }
    }
}

Models/Pages/HelloWorldPage.cs:

namespace DxcAlloy.Models.Pages
{
    [ContentType(DisplayName = "HelloWorldPage", GUID = "5e4176f9-613d-4c9e-9c85-37dd1d1d70d9", Description = "Hello World")]
    public class HelloWorldPage : PageData
    {

        [Display(
            GroupName = SystemTabNames.Content,
            Order = 10)]
        public virtual ContentArea ItemLiistContentArea { get; set; }
    }
}

Views/HelloWorldPage/index.cshtml

<div>
  Hello!
</div>

Any ideas?

#224522
Edited, Jun 22, 2020 9:32
Vote:
 

Hi,

Create the pageviewmodel first then pass it to view-

 public class HelloWorldPageController : PageControllerBase<HelloWorldPage>
    {
        public ActionResult Index(HelloWorldPagecurrentPage)
        {
            var model = PageViewModel.Create(currentPage);
            return View(model);
        }

    }

Index -

@model PageViewModel<EpiserverMeetup.Models.Pages.HelloWorldPage>

@Html.PropertyFor(x => x.CurrentPage.MainContentArea)
#224523
Edited, Jun 22, 2020 9:54
Vote:
 

Hi,

As I mentioned on your other thread, I suspect the issue you're seeing with the model type will be related to your layout file. The default layout in alloy expects a model of type IPageViewModel<SitePageData> and you're passing in just the HelloWorld page instance as a model. If you want to use the alloy layout file, you'll need to construct an instance if IPageViewModel in your controller as Ravindra suggests above and pass that as the model to your view. You will have an additional issue in doing that though in that PageViewModel.Create expects a page of a type which inherits from SitePageData which yours doesn't. You could modify your page type to inherit from SitePageData if that works for you or alternatively, if you don't want to change your type and you're happy not to use the alloy layout file, you could specify your own layout file in your view either as null to have no layout or pointed to a valid layout file which can handle a model of type HelloWorld or one of its ancestors (e.g. PageData).

#224526
Jun 22, 2020 11:59
* 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.