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.
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.
Example:
Model = MyCustomModel.cs
UserInformationModel = a object property in MyCustomModel.cs
userRole = a string property in my UserInformationModel.cs
@Model.UserInformationModel.userRole
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.
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:
From
To
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.
Example:
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.
from
to
Thanks for reading and hope someone could help me figure out how I can pass my CustomViewModel.cs with surfaceController.
is working on a reply...