asp.net-core-mvc-2.0

ImageProcessor.Web on .Net Core 2.0 project

流过昼夜 提交于 2019-12-25 19:35:51
问题 Can i use the imageprocessor.Web on .net Core 2.0 project even if the it's restored, targeting .NETFramework, Version=v4.6.1? Update On a fresh .Net Core 2.0 project the following Packages where installed: imageprocessor imageprocessor.web imageprocessor.web.config Normally on a Asp.net Mvc Template (framework=v4.6.1) by creating simple markup for images such as <img alt="Picture for category Electronics" src="http://localhost:15536/images/thumbs/0000005_electronics_600.jpeg?crop=0.5,0,0,0.1

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()

Get UrlHelper in middleware asp.net mvc core 2.0

北慕城南 提交于 2019-12-24 02:38:08
问题 How can I get UrlHelper in middleware. I try as below but actionContextAccessor.ActionContext return null. public void ConfigureServices(IServiceCollection services) { services.AddSession(); services .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(); services.AddMvc(); services.AddSingleton<IActionContextAccessor, ActionContextAccessor>(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure

Path based authentication in ASP.NET Core MVC 2.0

醉酒当歌 提交于 2019-12-22 12:37:17
问题 In ASP.NET Core MVC 1.1 we had path based authentication like this: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { // /api/* path app.UseWhen(ctx => IsApiRequest(ctx), subBranch => { subBranch.UseApiAuth(GetApiAuthOptions()); }); // else app.UseWhen(ctx => !IsApiRequest(ctx), subBranch => { subBranch.UseOpenIdConnectAuthentication(GetOpenIdOptions()); }); } Now we want to migrate it to ASP.NET Core MVC 2.0. In new version authentication

MVC Routing template to represent infinite self-referential hierarchical category structure

大城市里の小女人 提交于 2019-12-19 10:36:11
问题 I have a product category table to represent a hierarchical category structure, a typical Parent-Child relationship table in the database. Fill it with Guitar Center's data as an example: If you render them to a page with <ul> and <li> : Texts in blue are the URLs I would like to generate. For any given category, the link consists of its slug and its parents' slugs. Note that the example I listed only has 2 parent-child levels. In theory, with the self-referential structure, any child could

Localization in Asp.Net Core

我的梦境 提交于 2019-12-19 10:08:10
问题 I have been following the instructions on this page to setup Localization: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization However, for me it just doesn't seem to work. Here is what I have done: Startup.cs: public class Startup { public IConfigurationRoot Configuration { get; } public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", true, true); builder.AddEnvironmentVariables(

How to use DisplayTemplates in MVC core 2.0

拥有回忆 提交于 2019-12-12 10:53:30
问题 I used to use DisplayTemplates in MVC5 to get rid off foreach loops from views If I have a ProductDto and ProductController I would place a ProductDto.cshtml under Views/Product/DisplayTemplates/ or Views/Shared/DisplayTemplates/ to use the template for list of products: I would replace the foreach loops with the following line to list all products by using the template: @Html.DisplayFor(m=>m.Products); And if I want to use same model ( ProductDto ) in a different display template for

ASP.NET Core CreatedAtRoute No route matches the supplied values

本秂侑毒 提交于 2019-12-10 01:47:56
问题 Using ASP.NET Core 2.0.0 Web API, I'm trying to build a controller to do a database insert. The information can be inserted into the database just fine, but returning a CreatedAtRoute throws an 'InvalidOperationException: No route matches the supplied values.' Everything I've found online so far says this was a bug with early pre-release versions of ASP.NET Core and has since been fixed, but I'm not really sure what to do about this. The following is my controller code: [Produces("application

ASP.NET Core MVC Dependency Injection via property or setter method

只谈情不闲聊 提交于 2019-12-08 19:51:40
问题 It has been well documented, how to inject dependencies into services. Question: But is it (already) possible in ASP.NET Core 2.0 to have the system's DI mechanism automatically inject a service into a method or into a property? Sidenote: In PHP-Symfony this pattern is called setter injection. Example: Say I have a common MyBaseController class for all controllers in my project and I want a service (e.g. the UserManager service) to be injected into MyBaseController that can be later accessed

How to reference Microsoft.JQuery.Unobtrusive.Ajax within my ASP.NET Core MVC project

这一生的挚爱 提交于 2019-12-08 17:43:28
问题 I am trying to use Microsoft.JQuery.Unobtrusive.Ajax . I started by installing the package using NuGet and as expected I am able to see it among my dependencies. My problem is that I cant find a way to reference the script so I can use it within my view. Here I saw that I should add this to my layout: <script src="~/lib/Microsoft.jQuery.Unobtrusive.Ajax/jquery.unobtrusive-ajax.min.js"></script> but that path leads to no file: Here is my controller action: [HttpPost] public IActionResult