Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Alexander Mounzer 8 posts 118 karma points
    Jul 06, 2021 @ 06:57
    Alexander Mounzer

    Cannot bind source type Umbraco.Web.Models.ContentModel to model type ProjectName.ViewModels.<MyCustomViewModel>.

    I am curious to understand how I can pass my CustomViewModel to the view without invoking this ModelBindingException: Cannot bind source type Umbraco.Web.Models.ContentModel to model type legimusWeb.ViewModels.LoginViewModel.

    Whenever I use SurfaceController on my controller my view excepts Umbraco.Web.Models.ContentModel for this I can somewhat understand, I am guessing surfaceController wants me to send one of my built models to the view.

    I could fix this by changing my View:


     @inherits Umbraco.Web.Mvc.UmbracoViewPage<legimusWeb.ViewModels.LoginViewModel>


    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Login>

    But what happens now if I am using an API request to get xml or json information that I need to deseralize to an custom object and use this to create a condition on my view. It won't work.


    Model = MyCustomModel.cs UserInformationModel = a object property in MyCustomModel.cs userRole = a string property in my UserInformationModel.cs


    If I am using SurfaceController this is not possible due to @Model won't be referring to MyCusomtViewModel.cs but instead to the generated Login model.

    I could fix this by inherit the RenderMvcController in my controller class but that would mess up my routing to the different pages i want to navigate for the different userRole that exists in my API request.


      @AuthenticateController : SurfaceController


     @AuthenticateController : Umbraco.Web.Mvc.RenderMvcController

    Thanks for reading and hope someone could help me figure out how I can pass my CustomViewModel.cs with surfaceController.

Please Sign in or register to post replies

Write your reply to: