razor-pages

RazorPages with filenames that include a hyphen cause IntelliSense to break

Deadly 提交于 2019-12-11 14:38:49
问题 When using RazorPages with filenames that include a hyphen, it causes Visual Studio's tooling to show a red squiggly line on valid code. here are a few common errors I see: "The name ViewData does not exist in the current context" "The name TempData does not exist in the current context" "The name Model does not exist in the current context" For example, my RazorPage called Contact-Us.cshtml (with the hyphen) will error Whereas, my page ContactUs.cshtml (without the hyphen) will be fine.

.net core routing to a razor pages area based on current domain name?

折月煮酒 提交于 2019-12-11 10:43:46
问题 I'm currently trying to architect a application to host multiple websites from a single .net core application. Ideally, I would like to show completely different Razor pages based on the domain name the application is being accessed from. Ideally, I would like to have my razor pages broken down into areas, where each area is associated with a different domain name. IE www.domain1.com is the domain1 area, www.domain2.com is the domain2 area, and each area has it's own index about page etc. So

What is the difference between regular and Async methods (OnGet vs OnGetAsync)

拟墨画扇 提交于 2019-12-11 02:28:16
问题 I started learning how Razor Pages work, tutorials mention OnGet and OnPost, and also mention that we have async options too: OnGetAsync and OnPostAsync. But they don't mention how they work, obviously they're asynchronous, but how? do they use AJAX? public void OnGet() { } public async void OnGetAsync() { } 回答1: There is no actual difference between OnGet and OnGetAsync . OnGetAsync is just a naming convention for methods that contain asynchronous code that should be executed when a GET

Redirect user to page in a different ASP.NET Core Razor web site

落爺英雄遲暮 提交于 2019-12-10 22:49:34
问题 I have an ASP.NET Core 2.1 Razor app with two menu items that are active prior to login. I want to transfer (redirect?) to a different web site when either of the menu items is clicked. I've tried a Redirect, as shown below, but the current url is added to the string I specify. public IActionResult OnGet() { string url = "www.google.com"; return Redirect(url); } How can I do this? 回答1: It didn't take long to get the answer that was right in front of me anyway. Thanks to CodeCaster and Chris

Get version when using IPageRouteModelConvention

时光毁灭记忆、已成空白 提交于 2019-12-10 17:13:55
问题 I sometime ago asked how to add some kind of localized url's, were IPageRouteModelConvention came into play in a, for me, perfect way. With that I'm able to have routes in different languages/names. If I use www.domain.com/nyheter (swedish) or www.domain.com/sistenytt (norwegian) I still only find, in RouteData , that the News route were used ( RouteData.Values["page"] ). How do I get which version? I know I can check/parse the context.Request.Path but am wondering if there is a built-in

ASP.NET Core : Generate Razor Pages for all models

百般思念 提交于 2019-12-10 15:00:06
问题 I have created a ASP.NET Core 2.1 project With "Database first" approach and Razor Pages (no MVC). All my models are generated from the database context. I successfully created CRUD Razor Pages for one of my models with a command line like this one : dotnet aspnet-codegenerator razorpage -m Student -dc RazorDemoContext -udl -outDir Pages\Students I have approximatively 50+ models. Is there a command line to generate CRUD Razor Pages for all models at the same time and not just one by one ?

How to change starting page, using Razor Pages in .NET Core 2?

假装没事ソ 提交于 2019-12-08 17:30:28
问题 I wanted to set my starting page to /Members/Index. When I was using MVC, I configured it as following: app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Members}/{action=Index}/{id?}"); }); But now I'm trying new Razor Pages approach, and now Members is folder and Index is Razor Page. How to set this page in folder as starting one? I can add Index page in root directory and make redirect there, but I was looking for something cleaner. 回答1: For testing purposes

PageResult always returns null in IAsyncPageFilter - OnPageHandlerExecutionAsync in Asp.Net Core 2.0 Razor Pages

孤街醉人 提交于 2019-12-08 09:39:22
问题 I'm using a ModelValidationFilter to handle model validation errors for all my post or put requests. I'm using IAsyncPageFilter and registering as a global filter. In the OnPageHandlerExecutionAsync method, I'm able to handle the validation errors for ajax requests and send back a json response. But for non ajax request, I'm getting always null for var result = (PageResult)context.Result; Please could you assist me on this? I'm implementing this so that I don't need to write model validation

Form in Layout: Razor Pages

自闭症网瘾萝莉.ら 提交于 2019-12-08 07:17:24
问题 I have a select in a form in the Layout of my web app that needs to be accessible from every page. The form sets a session variable that is required to load data on every page. <form asp-page-handler="CustomerChange" method="post" class="navbar-form navbar-left"> <select name="Customer" id="Customer" class="form-control" onchange="this.form.submit()"> <option value="">Select Customer</option> <option value="Vand">Vandalay</option> <option value="Kram">Kramerica</option> </select> </form> I

Dropzone on razor Page returns 400 status code

喜你入骨 提交于 2019-12-08 05:13:27
问题 I am using DropZone on a RAZOR page in ASP.NET core 2.0 with other form inputs like this - DzDemo.cshtml Page - <form method="post" enctype="multipart/form-data"> <input type="text" id="Username" name="Username" /> <div class="dropzone" id="my-dropzone" name="mainFileUploader"> <div class="fallback"> <input name="file" type="file" multiple /> </div> </div> </form> <div> <button type="submit" id="submit-all"> upload </button> </div> JS:- Dropzone.options.myDropzone = { url: "/DzDemo?handler