I'm trying to achieve overriding of existing 'Theme' pages, located in 'Pages/Theme', by placing another page with the same name in the 'Pages/Overrides' folder.
I have done so by creating a PageRouteModelConvention named ThemeTemplatePageRouteModelConvention. Any pages in the 'Pages/Overrides' folder will be reachable without the '/Overrides/' route prefix and have priority over the similarly named view in the 'Pages/Theme' folder.
See my example repository here: https://github.com/bryandh/razor-page-override
In the current setup, we have three pages in Pages/Theme:
Index
About
Contact
And two pages in Pages/Overrides:
Index
About
The behaviour that I would like to have with these pages:
Index page with / route used from Pages/Overrides
About page with /about route used from Pages/Overrides
Contact page with /contact route used from Pages/Theme
This works as I want it to work.
However, the anchor tags created in the Pages/Theme/Components/_Header partial to a non-overriden page in Pages/Theme using the anchor tag helper does not create the correct route.
See the root/index page where the _Header component is included. The About page link is generated correctly as the About page is also in the same folder. However, the Contact page link does not seem to be generated properly. This link to the Contact page only works when you're on the Contact page itself, as that is situated in Pages/Theme.
Generation of the anchor tag doesn't seem to take the locations views can be situatied in into account.
Because the link is in a component that I do not want to override, I can't modify the asp-page attribute to fix the problem.
How can I let the Header component generate a link to the Contact Theme page from the overriding Index page?
[UPDATE]
To clarify further, see the page override structure below.
The asp-page tag helper can't find the Contact page to create a route for.
Note: the Contact page is reachable by manually navigating to /contact.
Related
I wonder if I could get some ideas on how best to approach this.
I have a Razor Pages application. I have several areas, and each area has its own layout page and menus.
This is pretty straight forward, but I have a couple of pages I need to share with two or more areas. These shared pages will be passed an argument that indicates which area it's being used by, and I would want the layout page (menu) for that page to be the one for that area. (Ideally, the URL would also reflect the current area.)
I'm not sure if this is practical. I'd like to keep things as simple as possible. But all I come up with is some fairly complex routing stuff.
Two options I can think of:
Put the shared page in the root Pages folder and use AddPageRoute to add multiple routes to the shared page including a parameter for the area name:
options.Conventions.AddPageRoute("/SharedPage", "{areaName}/alias1");
options.Conventions.AddPageRoute("/SharedPage", "{areaName}/alias2");
You can set the layout based on the value of RouteData.Values["areaName"]. Don't use area as the parameter name. It's a reserved word as far as routing is concerned:
#{
if(RouteData.Values["areaName"] == "foo")
{
Layout = "_FooLayout";
}
if(RouteData.Values["areaName"] == "bar")
{
Layout = "_BarLayout";
}
}
Add pages to the areas that act as placeholders to generate the routes, and then extract the body of the shared page to a partial that can be placed in the top level Pages/Shared folder so that it is accessible to all other pages in the application. If you want to centralise some of the processing for the shared page, create a class that inherits from PageModel and put your processing logic there, then have the actual PageModel classes inherit from that.
You can make this by using partial views.
So, create one patial view and place it not in areas (in Common for example or other folders).
In areas folder create master view that render only your Partial view.
So I have a link in my header placeholder in my MasterPage that takes me to my gallery
<a href="Gallery.aspx" class="logo-text">
Link is:
http://localhost:50803/Gallery.aspx
I created a subfolder called "Order" and used the MasterPage in one of the pages
Then I tried clicking the link in my header and it took me to
http://localhost:50803/Order/Gallery.aspx
Is there any way to change it so it takes me to the intended link?
I am confused on how to call or create server/controller methods in razor pages. When I do MVC, I would create methods in the controller and would use an anchor tag to call it like this:
<a href="/Security/LogOut/">
How do I do this in razor pages? I ended up creating a new page name "SignOut" and implemented the login inside the OnGet and used an anchor tag like this:
<a href="/SignOut">
What if I have more than one action method I want to group in a file? Do I need to create a page for every action?
You've probably long since found the answer you were looking for. For others that see this question, you can use:
<a asp-page="/SignOut">Sign Out</a>
In the case of Razor Pages, the GET and POST methods are handled by each code-behind file. For instance, for the Razor Page Details.cshtml, there is a code-behind file called Details.cshtml.cs that defines OnPostAsync and OnGetAsync which handle POST and GET requests respectively. For more information, see:
Microsoft Razor Pages Tutorial
I have a master detail page as the root page for my application. As a detail page for that I have a tabbed page. In the tabbed page I have a content page and a navigation page containing one content page. In the master detail's OnNavigatedTo I'm retrieving some organisation data from the cloud and then I want to navigate to a manage organisation page which is the plain content page in the tabbed page.
Using NavigateAsync and a relative uri to the manage organisation page I find that the Tabbed Page OnNavigatedTo is hit twice and then I get an exception such as (simplified) below. I can also see Binding errors in my output showing that elements on my manage organisation page xaml tried to bind to the tabbed page view model.
I'm not sure if this is an issue with the view model auto wire change in 6.2 or if it's a deep linking issue or if I've done something wrong.
"Sequence contains no elements".
at System.Linq.Enumerable.Last[TSource] (IEnumerable`1 source) [0x00079]
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnAttachedToWindow () [0x00011]
in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:189
Using XF 2.3.1.114, Prism.Forms 6.2, I'm not sure if other packages are relevant. If you think so I can include them.
Also interestingly, it works if I try navigate to the content page in the navigation page from the master detail i.e. "TabbedPage/NavigationPage/ContentPage".
Any ideas what the problem might be?
So first thing first, you don't have the proper XAML syntax for your TabbedPage. When defining the default page for a NavigationPage in XAML you must supply the page via the Arguments element:
<views:SimpleNavPage Title="Foo">
<x:Arguments>
<views:NestedContentPage />
</x:Arguments>
</views:SimpleNavPage>
You must also have the proper ctor in your navigation page:
public SimpleNavPage(Page root) : base (root)
{
InitializeComponent();
}
Now, I personally don't recommend navigating within the OnNavigatedTo unless you can absolutely guarantee that you will not be adding that page in another deep link, or navigation scenario. Imagine you start out with NavigateAsync("MainPage") and that has an OnNavigatedTo that does a deep link navigation operation. Now you decide to NavigateAsync("SomeOtherPage") in which it NavigateAsyc("AnotherPage/MainPage/SomeOtherPage/LastPage") from within it's OnNavigatedTo. Now, you will have created an issue because the MainPage.OnNavigatedTO will have kicked off another navigation operation while you are still navigating to the next "SomeOtherPage". You are asking for trouble.
I am trying to create a website that will allow sharing photos (as a basic project),
and i encountered a problem.
On my masterPage there are links with category names and I need that when i click on one of them I would get a Value into a variable in a child page (in the css code page).
I am pretty new to masterpages and have no idea how to do so, i tried in some ways but just couldn't.
As an example:
A string variable in the css section of the child page "Gallery.aspx" that would get the value of the category name when it's clicked in the masterpage.
Hyperlink hh=(Hyperlink)Master.FindControl("control_name");
reference