asp.net-core-mvc

TagHelper for passing route values as part of a link

房东的猫 提交于 2019-12-20 09:56:11
问题 When specifying asp-controller and asp-action on a link, what's the syntax for also passing an id attribute? E.g. If I wanted to link to the edit URL for a given object, the required URL would be /user/edit/5 for example. Is there a method to achieve this using TagHelpers, or do we still have to fall back to @Html.ActionLink() ? 回答1: You can use the attribute prefix asp-route- to prefix your route variable names. Example: <a asp-action="Edit" asp-route-id="10" asp-route-foo="bar">Edit</a> 回答2

How to protect a Web API using ASP.NET 5 MVC 6

谁都会走 提交于 2019-12-20 09:36:50
问题 I have a nice ASP.NET 5 / MVC 6 app up and running. Essentially for this purpose it is just the normal sample app you get when you start a new project to keep it simple. So far I can: Register a user Login Logout Protect a page (forcing login etc) Now, what I would like is to provide an API mechanism for a app to login and get an authentication token. Specifically I am working on two mobile apps to test with, one using Angular / Cordova and one using Xamarin. I have looked high and low and I

Any samples for mvc6 with signalr?

橙三吉。 提交于 2019-12-20 09:17:44
问题 I have a full-working ASP.NET MVC application (.NET Core, ASP.NET MVC 6) . I would now like to add a signalr to my application. Any samples for MVC with signalr ? 回答1: The MusicStore sample on GitHub use signalR and the BugTracker sample also and you have a sample in the SignalR-Server repo Or you can look at my sample on GitHub 回答2: I don't believe there are any yet. The next version of SignalR, version 3, is designed for ASP.NET Core, SignalR 2 doesn't support this. If you look on the ASP

Asp.Net 5 MVC 6 detect mobile browser

心不动则不痛 提交于 2019-12-20 09:14:48
问题 How is it possible in Asp.Net 5 MVC 6 to detect if the user is on a mobile device? In previous version of Asp MVC it could be done like this: Request.Browser.IsMobileDevice The problem is that the namespace System.Web is not used by Asp.Net 5 . The Request variable in the controller actions is now of type Microsoft.AspNet.Http.HttpRequest , the old version was of type System.Web.HttpRequestBase. Microsoft.AspNet.Http.HttpRequest does not contain the Browser property. I tried looking through

Asp.Net 5 MVC 6 detect mobile browser

微笑、不失礼 提交于 2019-12-20 09:13:18
问题 How is it possible in Asp.Net 5 MVC 6 to detect if the user is on a mobile device? In previous version of Asp MVC it could be done like this: Request.Browser.IsMobileDevice The problem is that the namespace System.Web is not used by Asp.Net 5 . The Request variable in the controller actions is now of type Microsoft.AspNet.Http.HttpRequest , the old version was of type System.Web.HttpRequestBase. Microsoft.AspNet.Http.HttpRequest does not contain the Browser property. I tried looking through

Injecting multiple implementations with Dependency injection

安稳与你 提交于 2019-12-20 08:55:39
问题 I'm currently working on a ASP.NET Core Project and want to use the built-in Dependency Injection (DI) functionality. Well, I started with an interface: ICar { string Drive(); } and want to implement the ICar interface multiple times like public class BMW : ICar { public string Drive(){...}; } public class Jaguar : ICar { public string Drive(){...}; } and add the following in the Startup class public void ConfigureServices(IServiceCollection services) { // Add framework services. services

Redirect to action after finishing background task queue

佐手、 提交于 2019-12-20 06:23:03
问题 I'm working on a .Net core solution that takes backup of storage files from another microservice and because this process takes too long time, we decided to build this routine under a background task.By following this link: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.1 I have implemented the background by using Queued background tasks like the following : public interface IBackgroundTaskQueue { void QueueBackgroundWorkItem(Func

Problems with Post Ajax in Asp.net core MVC

萝らか妹 提交于 2019-12-20 06:19:10
问题 I can not send a Model that I am manually creating to my controller. When I send the request, it's coming up with empty properties. There is something wrong that is hindering the conversion. Does anyone know how to help me? var operadoraChamadas = { Id: 0, Descricao: 'rssrrssr', PadraoSistema: true }; var requestData = { operadoraChamadasViewModel: operadoraChamadas} $.ajax({ url: "/pessoa-gerenciar/changeFormaContato", type: "POST", data: JSON.stringify(requestData), contentType:

Setting ASP.NET Core TagHelper Attribute Without Encoding

こ雲淡風輕ζ 提交于 2019-12-20 04:53:55
问题 I want to add the integrity attribute to a script tag in my tag helper. It contains a + sign which I don't want encoded. <script integrity="sha384-Li9vy3DqF8tnTXuiaAJuML3ky+er10rcgNR/VqsVpcw+ThHmYcwiB1pbOxEbzJr7"></script> This is my tag helper: [HtmlTargetElement(Attributes = "script")] public class MyTagHelper : TagHelper { public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { // Omitted... output.Attributes["integrity"] = "sha384

How to use yarn in ASP.Net core MVC to install bootstrap in wwwroot folder

本小妞迷上赌 提交于 2019-12-20 03:52:15
问题 recently I started learning ASP.Net core MVC. I always used bower to install packages for my projects in Visual Studio 2017. but now I want to use yarn. since it seems bower is deprecated. but I don't know how to use yarn to install bootstarp in wwwroot folder. for bower i used bower.json and it would install bootstarp automatically. I use "yarn add bootstrap@4.0.0-alpha.6 --dev" but it install it in node_modules in the project folder and I can't see it in the solution explorer, thanks 回答1: