razor-pages

How can I keep my model in my View after OnPost?

孤者浪人 提交于 2021-02-18 07:44:16
问题 I'm on a project with .Net Core and I'm using ASP Razor Pages. In my model, I have an OnGet which load all the data I need in my view. public IList<Projet> Projets { get; set; } public ActionResult OnGet() { Projets = _serviceSelect.getProjets(); return Page(); } Then, in my OnPost which is activated when I submit my form. <form method="post"> <div asp-validation-summary="All" class="text-danger"></div> <input type="radio" value="1" asp-for="LoginData.TypeCompte" />choice<br /> Username:

Render a Partial View in _layout.cshtml using the partialview model instance with DBContext dependency injection

瘦欲@ 提交于 2021-02-16 13:37:04
问题 At first I'd like to say I'm new to Asp.net Core and also with concepts of dependency injection (DI). I'm reading a lot trying understand it, so I ask for patience. I'm trying Razor Pages (not MVC) and my goal is to render to "_layout.cshtml" a partial view, in which information obtained using the Entity Framework is available on all pages. I added the DBContext in the Startup.cs file as follows: services.AddDbContext <AppDBContext> (options => options.UseSqlServer (Configuration

How to redirect .ASPX pages to .NET Core Razor page

ぃ、小莉子 提交于 2021-02-11 14:57:32
问题 We are moving a big asp.net web site to .NET Core Razor pages site. All over the internet there are links that point to our site and we want those links to work after our migration. We will kept the same url format, but without the extension .aspx. Summary, we want our old url: example.com/item.aspx be handle by .net core razor page, as example.com/item 回答1: You could use the URL Rewriting Middleware to remove the ".aspx" extensions. Check the following code: Use AddRedirect to create a rule

Submitting data from a Bootstrap modal popup

耗尽温柔 提交于 2021-02-11 14:00:57
问题 I'd like my users to be able to submit data from a Bootstrap modal popup. I'm wondering if anyone has experience doing this, and how you posted the data back to the server. Razor Pages have a lot of structure in place to deal with errors, etc. and it seems like you'd lose all that. Did you place the <form> tag right inside the modal popup? In this case, it appears there is no way to handle server-side errors. (Or did you find a way?) Or did you submit the data using AJAX, which requires some

ASP.NET Core 3.1 - Access denied

烈酒焚心 提交于 2021-02-11 13:50:23
问题 I'm quite new in ASP.NET Core 3.1 Razor Pages and I have a question. Hopefully you can help me further :). What I want to have is an application with Windows AD Security. Description of what I want to do: Customer needs to login using his/her AD account. The user is authorized if entered a valid AD account/password combination. The user have rights to see/adjust specific pages if in a specific group, let's say if in the Administrators group of the server where the application is running on.

ASP.NET Core ViewData, BindProperty or TempData?

喜欢而已 提交于 2021-02-08 05:39:18
问题 In ASP.NET Core Views and Razor Pages we can use: public class LoginModel { [BindProperty] public bool DisplayCaptcha { get; set; } // OR [ViewData] public bool DisplayCaptcha { get; set; } // OR [TempData] public bool DisplayCaptcha { get; set; } } To share data between View/Page/Controller... But when to use each one? In my case its a simple login page and when user set a wrong password I will display a captcha. In the form post i'm setting a property to true ( DisplayCaptcha = true ) and

Multiple routes to the same razor page

穿精又带淫゛_ 提交于 2021-01-29 22:32:58
问题 Background I've got a razor page in my Asp.Net Core 3.1 website called SignupAndApply. It's effectively a copy and paste of the register identity page but: With some additional fields Allows an optional applyid to be passed as part of the route If I pass an applyId as part of the route, I make a couple of label changes to the page and redirect the user somewhere else I want to create two routes for this page: /identity/account/signupandapply/{applyId?} 'when the user is applying and signing

Multiple routes to the same razor page

别等时光非礼了梦想. 提交于 2021-01-29 19:35:01
问题 Background I've got a razor page in my Asp.Net Core 3.1 website called SignupAndApply. It's effectively a copy and paste of the register identity page but: With some additional fields Allows an optional applyid to be passed as part of the route If I pass an applyId as part of the route, I make a couple of label changes to the page and redirect the user somewhere else I want to create two routes for this page: /identity/account/signupandapply/{applyId?} 'when the user is applying and signing

ASP.NET Core Razor pages - not binding on POST Request

試著忘記壹切 提交于 2021-01-29 12:59:55
问题 I have the following on my Login.cshtml.cs code file: Login.cshtml.cs public class LoginModel : PageModel { public string ReturnUrl { get; set; } public bool EnableLocalLogin { get; set; } = true; public string Username { get; set; } public string Password { get; set; } private readonly IIdentityServerInteractionService _interaction; public LoginModel(IIdentityServerInteractionService interaction) { _interaction = interaction; } public IActionResult OnGet(string returnUrl) { ReturnUrl =

Azure Storage FileShare with ASP.Net Core and Razor Page

走远了吗. 提交于 2021-01-29 09:28:48
问题 Beginner question I am using the latest ASP.NET Core SDK to build an MVC/Razor page to display user files. We have the files in Azure Storage FileShare. The difficulty I'm running into is getting the FILES to list out and there is very little documentation on how to do this out there. Once I finally get it figured out I would like to create a post on Medium or somewhere else to help any other beginners. The file structure of the File Share is as such: Azure File Share MainShare EmployeNumber