testing Razor Pages, RazorPageModel found but not view?

Vote:
 

I'm trying to use Razor Pages instead of good old MVC, and it seems to be should be supported through the use of RazorPageModel on the PageModel. I keep getting 404, and the PageModel.OnGet() never gets called.

    public class FrontpageModel : RazorPageModel<FrontPage>
    {        
        public PageResult OnGet()
        {
            return Page();
        }
    }

While debugging the HttpContext though, I found the ContentRenderingContext and the SelectedTemplate, which looks good. My FrontpageModel does indeed get registered as a TemplateModel for FrontPage, and it is selected when the content is requested. Path on the TemplateModel is null though. But the path for .cshtml view and razor page model is very much the same usually, just omit the .cs. The should be able to find it...

Tried to add a TemplateDescriptor with Path to the .cshtml file anyway, didnt work. it did get registered as a CustomAttribute on the type information, but it did not populate the Path property on the TemplateModel. 

Appreciate any tips, havent found any working code using RazorPageModel yet.

#271492
Edited, Feb 10, 2022 22:17
Vote:
 

Hi Karls

Where did you place your Razor page file? By default, the asp.net core runtime look for Razor page file in the /Pages folder.  I used Razor pages in one of my demo projects, it works fine. 

I hope it helps.

Cheers

#271530
Edited, Feb 11, 2022 1:55
Vote:
 

You're right of course, thank you! I was going for feature folders, and thought I tried with the /Pages folder after a while but I think I forgot to update model namespace after copying.. 

I'll have to figure out a custom convention for feature folders then, but thats a differen post on a differen forum I guess

#271539
Feb 11, 2022 10:32
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.