asp.net-core-mvc

Controller method doesn't catch object routes from redirect

风流意气都作罢 提交于 2021-01-27 18:12:19
问题 I'm sending data from form to my Test method and the data is there, If some error has occured, then I'm mapping my ModelInput to Model and then I'm performing an redirect to MyView with data sent via Object routes. For some reason in MyView param input is null, even if input in Test had correct values Any idea why after redirect my data (input param) is being lost? BTW: Guid? Id is sent correctly public IActionResult MyView(Guid? id, Model input = null) { // after redirect input is empty (...

Where is Request.Unvalidated on asp.net-core?

若如初见. 提交于 2021-01-27 12:52:56
问题 I have noticed that in classic ASP.NET MVC there is an Unvalidated property on Request which allows Access to raw values provided by the current request. I cannot identify this property on ASP.NET MVC Core . Is there still a way to Access that information? 回答1: ASP.NET Core doesn't have the same request validation feature as it was in ASP.NET. Here are team responses in GH issue: RequestValidation was always rather porous, and eventually we came to the realisation that validate should be an

Route action based on HTTP verb?

≡放荡痞女 提交于 2021-01-27 12:28:11
问题 I'm trying to get ASP.NET Core 2 MVC to route the action based on the HTTP verb via the following code in Startup.cs: app.UseMvc(routes => { routes.MapRoute( name: "post", template: "api/{controller}/{id?}", defaults: new { action = "Post" }, constraints: new RouteValueDictionary(new { httpMethod = new HttpMethodRouteConstraint("POST") }) ); routes.MapRoute( name: "delete", template: "api/{controller}/{id?}", defaults: new { action = "Delete" }, constraints: new RouteValueDictionary(new {

Can't set display format to 2 decimal places when using mvc6 grid

戏子无情 提交于 2021-01-27 12:23:25
问题 I need to display some average sums of currency values in my .net core asp mvc project. I am using mvc 6 grid to display the data, and I have tried these solutions: [DisplayFormat(DataFormatString = "{0:C}")] public double? AverageCost { get; set; } [DisplayFormat(DataFormatString = "{0:#.####}")] public double? AverageCost { get; set; } [RegularExpression(@"^\d+\.\d{0,2}$")] public double? AverageCost { get; set; } But still my values are displayed with several decimal places: Am I missing

Why aren't my IdentityRoles and ApplicationUsers populating into my database?

心不动则不痛 提交于 2021-01-27 07:10:43
问题 I am having trouble seeding users in my .net core 3.1 web app. The corresponding tables are being created on SQL Server, but no rows are being created when I run my app. I don't know why the database isn't being populated. Can anybody spot the issue? DBInitializer file to seed users into database public class DBInitializer { public static async Task Initialize(IServiceProvider services) { ApplicationDbContext database = services.GetRequiredService<ApplicationDbContext>(); UserManager

Do I need to add Async to my Controller Actions in Visual Studio 2017 ASP.NET Core MVC

天大地大妈咪最大 提交于 2021-01-27 05:24:49
问题 I just converted my Visual Studio 2015 ASP.NET MVC Core project to Visual Studio 2017...and I get the following Informational messages in my Error List Message IDE1006 Naming rule violation: Missing suffix: 'Async' This message occurs in my Controllers that focus on the following: public async Task<IActionResult> Index() This also applies to Create, Delete, Details and Edit. The messages show as Informational and applies to over 1,000 occurences in my project. It appears that I need to change

How to separate asp.net core mvc project into multiple assembly (.dll)?

此生再无相见时 提交于 2021-01-22 16:41:02
问题 How to separate asp.net core mvc project into multiple assembly (.dll)? I have 3 projects MyApp Project Controllers HomeController.cs Models Views Home Index.cshtml HR Project Controllers EmployeeController.cs Models EMPLOYEE.cs Views Employee Index.cshtml ACC Project Controllers ChartAccountController.cs Models ACCOUNT.cs Views ChartAccount Index.cshtml I want to compile into dll HR Project HR.dll HR.Views.dll ACC Project ACC.dll ACC.Views.dll I want to add reference those dll (HR.dll, HR

How to separate asp.net core mvc project into multiple assembly (.dll)?

旧巷老猫 提交于 2021-01-22 16:36:47
问题 How to separate asp.net core mvc project into multiple assembly (.dll)? I have 3 projects MyApp Project Controllers HomeController.cs Models Views Home Index.cshtml HR Project Controllers EmployeeController.cs Models EMPLOYEE.cs Views Employee Index.cshtml ACC Project Controllers ChartAccountController.cs Models ACCOUNT.cs Views ChartAccount Index.cshtml I want to compile into dll HR Project HR.dll HR.Views.dll ACC Project ACC.dll ACC.Views.dll I want to add reference those dll (HR.dll, HR

Inject generic interface in .NET Core

左心房为你撑大大i 提交于 2021-01-20 16:12:06
问题 I want to inject this interface to my controllers: public interface IDatabaseService<T> where T : class { T GetItem(int id); IEnumerable<T> GetList(); void Edit(T data); void Add(T data); void Remove(T data); } I want to use generic, because in my WebApi project i have controllers like ProjectController , TaskController etc and i want to use generic interface to each of type (for example, IDatabaseService<Project> , IdatabaseService<Task> etc). Class, that will be injected to controller will

Inject generic interface in .NET Core

心已入冬 提交于 2021-01-20 16:11:38
问题 I want to inject this interface to my controllers: public interface IDatabaseService<T> where T : class { T GetItem(int id); IEnumerable<T> GetList(); void Edit(T data); void Add(T data); void Remove(T data); } I want to use generic, because in my WebApi project i have controllers like ProjectController , TaskController etc and i want to use generic interface to each of type (for example, IDatabaseService<Project> , IdatabaseService<Task> etc). Class, that will be injected to controller will