-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Responsive Razor Pages View Location #297
Conversation
This PR is taking a lot of my time more than expected. Might need to move on and come back to later. |
@rynowak would you mind helping me out. Much appreciate if you can, because you are the original creator of I can ViewLocationExpander the Mobile viewTablet viewDesktop defaultThe |
The View Engine now needs to know about pages :(. This isn't ideal but the view engine needs to know what set of search paths to use. This was already hardcoded for controllers vs controllers + areas. It felt right to further hardcode instead of introduce a wierd abstraction that we only use. Additionally pages use a view location expander to implement an ascending directory search.
…en when it's surrounded by slashes.
yield return location.Replace("{0}", "{0}." + device); | ||
// Fallback to the original default view | ||
yield return location; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you manage to figure this out? Anything I can help with still?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please please help! I have my head spinning for a few days on this already. Much appreciated :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I'll take a look tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I see what's going on here.
We don't use view location expanders to locate the "view" for a Razor Page because we've already found it. The page itself is the "view" so we don't go through a lookup process. What you could do instead is use routing a select a different page.
The other problem that's solved by doing this selection in the routing layer is one you might not have noticed. Because you defined a page with the filename Index.mobile.cshtml
that means that it will respond to the url /Index.mobile
which is probably not what you wanted. Routing for pages is customizable to address all of this.
I've got a branch where I've coded this up. I'll send you a link, and I'm happy to answer whatever questions you have about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code awesome, its open my perspective.
I see you a create ResponsiveAttribute
, but see you use anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the convention for metadata types to use an attribute type. This would work for controllers as well. So if you had different action methods based on the device in use, that would "just work" with a controller as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the explanation.
This also me wanna to revisit another issue #243 Responsive Option to include Web Api Controllers. By using conventions pattern might be a better way then to pass in options.
Look like Layout is not working yet with Areas. Another todo
Better to see in the browser tab
return false; | ||
} | ||
|
||
public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CandidateSet
is another investing thing that need my further attention and study later.
https://github.com/dotnet/aspnetcore/blob/master/src/Http/Routing/src/Matching/CandidateSet.cs
@@ -0,0 +1,3 @@ | |||
@using RazorApp | |||
@namespace RazorApp.Pages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong namespace and causing render issues
{ | ||
if (!location.Contains("/{1}/") | ||
&& !location.Contains("/Shared/") | ||
&& !location.Contains("/Areas/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe another place to determine the issue.
src/Hosting/PageMatcherPolicy.cs
Outdated
internal class ResponsivePageMatcherPolicy : MatcherPolicy, IEndpointComparerPolicy, IEndpointSelectorPolicy | ||
{ | ||
public ResponsivePageMatcherPolicy() | ||
=> Comparer = EndpointMetadataComparer<IResponsiveMetadata>.Default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another thing that i need to investigate more EndpointMetadataComparer
Merged with #331 for OperatingSystem change to Platform
Investigate the following for convention for Areas |
Got a working concept with responsive razor pages using areas coming in with PR #339. mobiletablet |
Need to add unit tests and refactor later
Working concept with responsive razor pages using areas
@rynowak finally got it working for razor pages in areas too now.Thank you very much for your help to complete this feature of device responsive view for razor pages. Much appreciated 🥇 |
Reference #115