asp.net-core-mvc

In a view component invoked as a tag helper, how can we access the inner HTML?

China☆狼群 提交于 2019-12-24 08:57:22
问题 In tag helpers, we can access the tags inner HTML. <!-- Index.cshtml --> <my-first> This is the original Inner HTML from the *.cshtml file. </my-first> // MyFirstTagHelper.cs > ProcessAsync var childContent = await output.GetChildContentAsync(); var innerHtml = childContent.GetContent(); If we invoke a view component as a tag helper, how can we access the inner HTML? <vc:my-first> This is the original Inner HTML from the *.cshtml file. </vc:my-first> // MyFirstViewComponent.cs > InvokeAsync()

ASP.NET Core MVC FromService binding in Controller returns empty collection

落爺英雄遲暮 提交于 2019-12-24 08:22:19
问题 Been trying to get a grip of ASP.NET Core MVC but got stuck with dependency injection returning empty collection in my controller action, despite of registering the service as Singleton in ConfigureService method. Tried two different ways to register but only one of them actually works. Said method is as following: public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); /***THIS DOES NOT WORK***/ services.AddSingleton<IRepository<Employee>,

C# ASP.NET Core ModelBinder not Updating Model

☆樱花仙子☆ 提交于 2019-12-24 07:58:34
问题 I have created a ModelBinder, which only gets triggered if an object has a [Decimal] attribute assigned, yet for some reason, despite it actually sanitising the data it does not seem to update the posted model. I wonder if someone could see from my code below, where I maybe going wrong. Startup.cs public void ConfigureServices(IServiceCollection serviceCollection) { serviceCollection.AddMvc(config => config.ModelBinderProviders.Insert(0, new DecimalModelBinderProvider())); }

An error occurred attempting to determine the process id

爷,独闯天下 提交于 2019-12-24 07:45:25
问题 I keep getting the following error when I try to debug my .NET-Core application: An error occurred attempting to determine the process id of Test.exe which hosting your application I have googled around and I see many having this problem with SSL. But I don't have SSL. I have also tried to remove the json lock file, but that don't work either.. Should I modify something in project.json? Here is my project.json: { "userSecretsId": "aspnet-Testar-0b0a75f7-4784-4192-a127-a1a4183a2709",

Get scaffolder to generate fields in specific order

落爺英雄遲暮 提交于 2019-12-24 07:09:18
问题 I am trying to get asp.net core MVC to scaffold a Razor View with fields in a different order than the apparently default alphabetical order. I've got a simple model: public class Application : EntityBase { [Display(Name = "Naam", Order = 1)] public string Name { get; set; } [Display(Name = "Omschrijving", Order = 2)] public string Description { get; set; } } I want the scaffolder to generate a field for Name before Description. How to do this? I've been trying to come up with a solution in

ASPNET Core and localization with resx files

一曲冷凌霜 提交于 2019-12-24 06:40:42
问题 I cant get my resource files loaded, or some thing else is keeping my app to load correct values. This is from my Startup.cs: services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; }); services.AddMvc() .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, opts => { opts.ResourcesPath = "Resources"; }) .AddDataAnnotationsLocalization(); services.Configure<RequestLocalizationOptions>(options => { var supportedCultures = new[] { new CultureInfo("da-DK") }; options

MVC middleware check attribute on controller method

ぐ巨炮叔叔 提交于 2019-12-24 05:55:31
问题 I am using asp.net core mvc. Next to default authentification I have added very specific authorization which is done by using ResultFilterAttribute attribute. In future, to make sure that developers are going to specify permissions for each controller method I would like to check if the attribute is set for method, before action is executed. Can it be done in MVC middleware. Or maybe there is better approach? 回答1: Thanks to Christian for mentioning ControllerFactory . It was right approach in

How to use ASPNET BoilerPlate with Oracle Database

断了今生、忘了曾经 提交于 2019-12-24 03:59:27
问题 We are using .Net Core template of ASPNET BoilerPlate framework. It works fine with SQL Server, but now we need to use Oracle 11g instead. Is it possible? If yes, how can we implement it for our project? Thanks and sorry for my English. 来源: https://stackoverflow.com/questions/54840503/how-to-use-aspnet-boilerplate-with-oracle-database

Reload routes on runtime in dotnetcore

眉间皱痕 提交于 2019-12-24 03:53:26
问题 I have a custom route that reads URLs from a no-SQL database (MongoDB) and add them to the route pipeline at moment that the application starts, which is "pretty standard" something like this (in my startup.cs file): app.UseMvc(routes => { routes.MapRoute( "default", "{controller=Home}/{action=Index}/{id?}"); routes.Routes.Add( new LandingPageRouter(routes, webrequest, memoryCache, Configuration)); // this custom routes adds URLs from database } the issue is that if I add another route to the

.NET Core IHttpContextAccessor issue

柔情痞子 提交于 2019-12-24 02:16:52
问题 I have static helper class public static class Current { public static string Host { get { return "httpContextAccessor here"; } } } How I can get access to current HttpContext inside Host property? 回答1: You can't and you shouldn't. This beats the whole purpose of having a dependency injection system at all. Static classes (for runtime data or Service Locator) is an anti-pattern. In ASP.NET Core you have to inject IHttpContextAccessor in classes where you need it. You can make a non-static