asp.net-core-mvc

ASP.NET Core - Scaffold Identity like MVC

↘锁芯ラ 提交于 2020-08-24 06:01:19
问题 I have created a Web Application MVC project with Individuals User Accounts authentication. Afterwards I created a custom UserIdentity. I am trying to change the default "Register" view of Identity adding my new fields, however I only managed to scaffold new pages as Razor Pages. My question is: Is it possible to scaffold these new views in some structure like MVC? I would not like to mix MVC with Razor Pages at all. If this is not possible, is there any way to creating a controller that

How to implement dataTables Server side Side Paging/Searching/Sorting in ASP.net Core

亡梦爱人 提交于 2020-08-10 18:53:50
问题 I am trying to perform Searching, Sorting, Paging from server-side of jQuery Datatable, I have written Following Code but, i cannot get parameters for sorting, Searching From datatble to my MVC Controller. Here is my code. My datatable Looks Like... <script> $(document).ready(function () { $("#newT").DataTable({ ajax: { url: '@Url.Action("Prods", "NewTest")', method: 'post', dataType: 'json', dataSrc : '' }, columns: [ { title: 'Id', data: 'id', searchable: false, sortable: false, visible:

How to get TempData in an integration test

狂风中的少年 提交于 2020-08-07 04:53:27
问题 I have a controller with the following actions: [HttpGet] public IActionResult Index() { return View(); } [HttpPost] [Route( "/MyShop/OrderDetails/CancelOrder", Name = UrlRouteDefinitions.MyShopOrderDetailsCancelOrder)] [ValidateAntiForgeryToken] public IActionResult CancelOrder(MyViewModel viewModel) { var isCancelSuccessful = _orderBusinessLogic.CancelOrderById(viewModel.Order.Id); if (isCancelSuccessful) { //to show a success-message after the redirect this.TempData["SuccessCancelOrder"] =

Background task in asp.net core mvc 3.1

别来无恙 提交于 2020-08-05 13:29:13
问题 I want to run a background task in an asp.net core mvc application. Here is what i've done: in Startup.cs: public void ConfigureServices(IServiceCollection services) { ... services.AddHostedService<MyTask>(); } in MyTask.cs: public class MyTask: BackgroundService { ... public override async Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation("StartAsync"); } public override async Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("StopAsync"

Display asp-validation-summary on field change

霸气de小男生 提交于 2020-08-05 09:35:38
问题 Using ASP.NET Core unobtrusive client-side validation, I want to display the validation summary when a field changes, not just on form submit . The <div asp-validation-summary="All"></div> element displays relevant error messages for each field when the form is submitted, but not when the fields are modified (and the modified state is invalid). Here is my example code: My model: public class InviteNewUser { [DisplayName("Email Address")] [Required(ErrorMessage = "Please provide the invitee's

Override ValidateAsync in UserValidator.cs for .NET Core Identity 2.1

心不动则不痛 提交于 2020-08-02 20:53:48
问题 I'm customizing the validation for username to allow the same username (non-unique). This is with an additional field "Deleted" as a soft delete to identity user. So the customization involves changing the current validation to check if the username already exist and deleted is false to only trigger DuplicateUserName error. What I've done is create a CustomUserValidator class, and override the ValidateAsync method in UserValidator.cs as well as the ValidateUserName method. Below is the code:

Override ValidateAsync in UserValidator.cs for .NET Core Identity 2.1

末鹿安然 提交于 2020-08-02 20:50:27
问题 I'm customizing the validation for username to allow the same username (non-unique). This is with an additional field "Deleted" as a soft delete to identity user. So the customization involves changing the current validation to check if the username already exist and deleted is false to only trigger DuplicateUserName error. What I've done is create a CustomUserValidator class, and override the ValidateAsync method in UserValidator.cs as well as the ValidateUserName method. Below is the code:

ASP.NET Core 2.1: Navigating back to a page after an HTTP POST fails validation displays a browser error

不羁的心 提交于 2020-08-01 12:47:08
问题 Problem: Using an ASP.NET Core 2.1 MVC project, I'm receiving the following browser error message after using the browser back button to return to a form, where the form POST failed server-side validation: Error message in Firefox: Document Expired This document is no longer available. The requested document is not available in Firefox’s cache. As a security precaution, Firefox does not automatically re-request sensitive documents. Click Try Again to re-request the document from the website.

ValidateAntiForgeryToken in Ajax request with AspNet Core MVC

只愿长相守 提交于 2020-08-01 10:24:05
问题 I have been trying to recreate an Ajax version of the ValidateAntiForgeryToken - there are many blog posts on how to do this for previous versions of MVC, but with the latest MVC 6, none of the code is relevant. The core principle that I am going after, though, is to have the validation look at the Cookie and the Header for the __RequestVerificationToken , instead of comparing the Cookie to a form value. I am using MVC 6.0.0-rc1-final, dnx451 framework, and all of the Microsoft.Extensions

ValidateAntiForgeryToken in Ajax request with AspNet Core MVC

筅森魡賤 提交于 2020-08-01 10:23:16
问题 I have been trying to recreate an Ajax version of the ValidateAntiForgeryToken - there are many blog posts on how to do this for previous versions of MVC, but with the latest MVC 6, none of the code is relevant. The core principle that I am going after, though, is to have the validation look at the Cookie and the Header for the __RequestVerificationToken , instead of comparing the Cookie to a form value. I am using MVC 6.0.0-rc1-final, dnx451 framework, and all of the Microsoft.Extensions