razor-pages

Routing Razor Pages to /example.com/en/ format

核能气质少年 提交于 2020-06-27 04:25:18
问题 I have three languages on my website. I'm trying to get my razor pages to route to culture/localization like so: https://localhost:44396/en/ https://localhost:44396/ru/ I have hundreds of lines of code commented out at this point using methods I've been googling for the past two days and nothing seems to do the job. The website is mostly static so right now beyond the culture there is nothing else that needs routing. 回答1: Here's a way you can do it that doesn't require you to put a middleware

Can you use IAsyncEnumerable in Razor pages to progressively display markup?

六月ゝ 毕业季﹏ 提交于 2020-06-10 16:54:50
问题 I've been playing around with Blazor and the IAsyncEnumerable feature in C# 8.0. Is it possible to use IAsyncEnumerable and await within Razor Pages to progressively display markup with data? Example service: private static readonly string[] games = new[] { "Call of Duty", "Legend of Zelda", "Super Mario 64" }; public async IAsyncEnumerable<string> GetGames() { foreach (var game in games) { await Task.Delay(1000); yield return game; } } Example in razor page: @await foreach(var game in

Can you use IAsyncEnumerable in Razor pages to progressively display markup?

社会主义新天地 提交于 2020-06-10 16:49:28
问题 I've been playing around with Blazor and the IAsyncEnumerable feature in C# 8.0. Is it possible to use IAsyncEnumerable and await within Razor Pages to progressively display markup with data? Example service: private static readonly string[] games = new[] { "Call of Duty", "Legend of Zelda", "Super Mario 64" }; public async IAsyncEnumerable<string> GetGames() { foreach (var game in games) { await Task.Delay(1000); yield return game; } } Example in razor page: @await foreach(var game in

400 Bad Request when POST-ing to Razor Page

倾然丶 夕夏残阳落幕 提交于 2020-06-10 02:59:27
问题 My page has... @page "{candidateId:int}" ... and @Html.AntiForgeryToken() Model has... public void OnGet(int candidateId) { } public void OnPost(int candidateId) { } GET works fine. Here is my AJAX request.. $.ajax({ type: "POST", url: "/Skills/" + candidateId, beforeSend: function (xhr) { xhr.setRequestHeader("XSRF-TOKEN", $('input:hidden[name="__RequestVerificationToken"]').val()); }, data: { name: 'hi mum' }, success: function (response) { }, failure: function (response) { alert(response);

400 Bad Request when POST-ing to Razor Page

落花浮王杯 提交于 2020-06-10 02:59:04
问题 My page has... @page "{candidateId:int}" ... and @Html.AntiForgeryToken() Model has... public void OnGet(int candidateId) { } public void OnPost(int candidateId) { } GET works fine. Here is my AJAX request.. $.ajax({ type: "POST", url: "/Skills/" + candidateId, beforeSend: function (xhr) { xhr.setRequestHeader("XSRF-TOKEN", $('input:hidden[name="__RequestVerificationToken"]').val()); }, data: { name: 'hi mum' }, success: function (response) { }, failure: function (response) { alert(response);

IList returning count=0 on posting back updated checkboxes

给你一囗甜甜゛ 提交于 2020-06-01 06:46:05
问题 I'm using asp.net-core with razor pages. I'm trying to update the checkboxes in the table. When clicking on button save I pass with asp-route-for because I want to know how many items are in the list But my IList usersAccessRights is returning count = 0 and skips my foreach in update function. Is there other way to receive how many items and update the table checkboxes? cshtml.cs: public IActionResult OnPost(int id, string groupAccessName, bool chkDefaultGroup, IList<OutputAccessRights>

How do you launch a background process in ASPNET Core 3.0?

女生的网名这么多〃 提交于 2020-05-31 01:56:13
问题 I know that the new ASPNET Core 3.0 stack has a number of improvements around hosting processes. I am curious about the best way to be able to define and execute a background process from a Razor PageModel? Meaning I have some logic that needs to start something in the background and then that Razor page doesn't need to monitor it's outcome, but I would like to be able to observe it too if that's not too hard. Can someone show me a code sample or point me in the right direction? 回答1: Since

Binding radio buttons in ASP.NET MVC page with razor

孤人 提交于 2020-05-30 08:11:11
问题 I have a page with 4 radio buttons (Exam question and 4 options to choose from). With the code below, I can read the option values after user clicks the button. I have two questions: Why are all radio buttons selected when the page first loads? How to find out which radio button is selected after the post? Thanks! StudentQuestions.cshtml @page "{examId:int?}" @model VerityLearn.WebUI.Pages.Questions.StudentQuestionsModel @{ ViewData["Title"] = "StudentQuestions"; } <div> <form method="post">

How can I set up conditional Layouts with _ViewStart in ASP.NET Core Razor Pages?

怎甘沉沦 提交于 2020-05-28 07:57:34
问题 I want to display different layouts based on the current rendered Page. I can't find anything online about this but I feel like this should be an extremely common use case. I only have a few pages. I would like to assign unique layouts to both my Register and Login pages. This is what I've got so far but I am unable to use the ControllerContext in this situation. @{ string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); dynamic Layout; switch (controllerName

Server-side Blazor page post to Razor page http error 400

只谈情不闲聊 提交于 2020-05-16 12:31:42
问题 I am trying to post my username and password from a Blazor page (.razor) to a Razor Page(.cshtml) but I get http error 400 all the time. LoginControl.razor <form method="post" action="login"> <input type="text" name="username" @bind="@Username" placeholder="User Name" />    <input type="password" name="password" placeholder="Password" @bind="@Password" />    <button class="ml-md-auto btn btn-primary">Loggin</button> </form> Login.cshtml.cs public async Task<IActionResult> OnPostAsync(