YAFLogo

rico515
  • rico515
  • 62.8% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4
a year ago
How can I add custom pages to the source code? I'm used to Blazor, where I would add a CustomPage.razor file, and add routing with:


@page "/CustomPage"

Then add cshtml in the same file with C# code within a code block with:


<h3>Custom Page </h3>
<EditForm Model="RequestObject" OnValidSubmit="@GetResponse">
<input @bind-value="RequestObject.RequestProperty"></input>
<button type="submit">Submit</button>
</EditForm>
<div>Result: @result</div>
@code{
[inject]
private IMyClient APIClient
private string result = "";
private async Task<string> GetResponse(RequestObject requestObject) => APIClient.SendRequest(requestObject);
}

I'm confused by the source code cshtml files with '@page "{t:int}/{handler?}"' and the '@model EmailTopicModel'

My questions: 

1. What is the {handler?} part of the route? Can I just route with @page "/CustomPage"?

2. Do I put my C# in a Model class and reference that from the page file or can I use a @code{} block?

3. How do I pass data between the backend and frontend code to and from API calls? 

Any help or resources would be much appreciated!

 

Sponsor
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
a year ago
1. yes you can just use @page "/CustomPage" if you want to know more on what handler means and the other routing options you may want to read this page...

https://www.learnrazorpages.com/razor-pages/routing 

2. You can do both. Whatever you prefer.

3. Check again the website https://www.learnrazorpages.com/razor-pages/model-binding  for binding and retrieving data.

rico515
  • rico515
  • 62.8% (Friendly)
  • YAF Forumling Topic Starter YAF Version: 4
a year ago
Thank you for your reply! The resources are very helpful.

Could you please help me understand how auth works within routing? I'm trying to understand how pages are locked down with user context, and I'm not seeing it. For example, for the route ending in Admin/Admin, how does the app make sure the user is an admin? Does the HTML at the bottom of the page display when they are not? I don't see where the router or the page itself would check whether the user is Admin, and I would like to add pages only accessible by admins. 

Bottom Admin/Admin HTML

<div class="row justify-content-end">
    <div class="col-auto">
        <pager page-size="@Model.Input.UnverifiedPageSize"
               count="@Model.Input.UnverifiedCount"
               query-name="p2">
        </pager>
    </div>
</div>
 
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2