HtmlHelper is unable to get correct model in Umbraco 10 MVC views
Issues with customized MyRenderController (RenderController) and template in Umbraco10:
Template: @inherits UmbracoViewPage
If using HtmlHelper inside the view, model for HtmlHelper is dynamic instead of MyPage. When hovering 'Html' text over @Html.BeginForm(m => m...), showing "htmlhelper
unable to access any properties from MyPage.
But @Model is MyPage
Is anyone able to use HtmlHelper in Umbraco 10 MVC views?
Unfortunately 8 and 10 are completely different beasts and just because it works in 8 does not mean it will in 10. Having said that, there is no reason what you are trying should not work.
Try clearing any temp/cache data and ensure all your using statements are correct.
Understood, our umbraco 10 project was completely re-created for .net 6
What I meant was - the customized model class, view and controller were re-created the similar way as in Umbraco 8. But Htmlhelper is not getting the model for UmbracoViewPage umbraco 10 by the code below
I'm seeing Postback a SurfaceController action ("SubmitSigninForm") within the view. What is the model type for IHtmlHelper when hovering mouse over 'Html.BeginUmbracoForm", is it 'NoLayout'?
The form is for a surface cotroller yes, what are you using the MVC controller for maybe if you posted your code it would be easier to offer some help.
HtmlHelper is unable to get correct model in Umbraco 10 MVC views
Issues with customized MyRenderController (RenderController) and template in Umbraco10:
Template: @inherits UmbracoViewPage
If using HtmlHelper inside the view, model for HtmlHelper is dynamic instead of MyPage. When hovering 'Html' text over @Html.BeginForm(m => m...), showing "htmlhelper
unable to access any properties from MyPage.
But @Model is MyPage
Is anyone able to use HtmlHelper in Umbraco 10 MVC views?
I think you may should do this
also, what do you have your models builder set to? If it is InMemory then you won't have access to the strongy typed model.
Thanks Huw! I did use the following in view (it didn't display correctly for some reason).
@inherits UmbracoViewPage< MyPage >
I tried all setting options (Nothing, InMemoryAuto, SourceCodeManual, SourceCodeAuto) for models builder, all with the same result for HtmlHelper -
error CS1963: An expression tree may not contain a dynamic operation
PS, we are actually migrating our site from umbraco 8 to 10, all code works fine in umbraco 8.
Unfortunately 8 and 10 are completely different beasts and just because it works in 8 does not mean it will in 10. Having said that, there is no reason what you are trying should not work. Try clearing any temp/cache data and ensure all your using statements are correct.
Understood, our umbraco 10 project was completely re-created for .net 6
What I meant was - the customized model class, view and controller were re-created the similar way as in Umbraco 8. But Htmlhelper is not getting the model for UmbracoViewPage umbraco 10 by the code below
Seems to me Htmlhelper only works when declaring model class explicitly, which will not work for Umbraco RenderController/View
Thanks for your reply!
Mmmm, not sure then, you should be abe to do what you want without a problem
(example code form one of my views)
I'm seeing Postback a SurfaceController action ("SubmitSigninForm") within the view. What is the model type for IHtmlHelper when hovering mouse over 'Html.BeginUmbracoForm", is it 'NoLayout'?
No, it is MvcForm which is what I would expect it to be
Thanks. Your example is a view/form for SurfaceController, mine is MVC controller/view.
The form is for a surface cotroller yes, what are you using the MVC controller for maybe if you posted your code it would be easier to offer some help.
Code is very simple as attached, model is supposed to be "ASICompLogin", but it is actually "dynamic" for HtmlHelper.
But razor "Model" is correct type, as attached in this second screenshot.
OK, I see now. Is there any reason you are not using
rather than just Html.BeginForm ?
We have quite some MVC RenderControllers with different views in our Umbraco 8 application. I don't see why they could not be used in 10.
Regarding SurfaceController post action(BeginUmbracoForm), did you ever encounter the error below?
"No service for type "MySurfaceController" has been registered"
yes if using the form in a viewcomponent, there is an existing post discussing it and the solution
is working on a reply...