asp.net-core-mvc

Asp.net MVC putting checkbox data in a list of booleans

你说的曾经没有我的故事 提交于 2019-12-10 11:15:16
问题 I am trying to bind unknown amount of checkboxes to a list of booleans. After hours of searching I havn't found any solution. This is the relevent part of code in my view: @foreach (Device d in Data.GetDevices()) { <label asp-for="NewRegistration.Devices">@d.Name</label> <input asp-for="NewRegistration.Devices" class="checkbox" type="checkbox" /> } The loop works but when i changed the type if the input to checkbox it gave me this exeption: InvalidOperationException: Unexpected 'asp-for'

In ASP.net 5 MVC 6 , How to use same controller name in different namespaces

允我心安 提交于 2019-12-10 11:07:02
问题 I defined two controller with same controller name in different namespaces. And got an exception. How to uer parameter "dataTokens" to define namespace of controller like mvc-4? Exception below: AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied: Alice.Controllers.TestController.Index Alice.Controllers.Api.TestController.Index Microsoft.AspNet.Mvc.Infrastructure.DefaultActionSelector.SelectAsync(RouteContext context)

@addTagHelper could not load file or assembly

人盡茶涼 提交于 2019-12-10 10:44:04
问题 I have an ASP.NET core project generated with Yeoman generator-aspnet. My problem is that I can't use the generator provided tag helper (and my test tag help doesn't work either). The project name is react_tests , and this is the _ViewImports.cshtml file @using react_tests @using react_tests.Models @using react_tests.Models.AccountViewModels @using react_tests.Models.ManageViewModels @using Microsoft.AspNetCore.Identity @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *,

Claims on signin in .NET Core RC2

感情迁移 提交于 2019-12-10 10:07:57
问题 I'm porting a .NET 4.6 version to .NET Core RC2 and wondering how to do following in .NET Core RC2. public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); userIdentity.AddClaim(new Claim("FullName", string.Format("{0} {1}", this.Firstname

How to Update Model in ASP NET MVC 6?

大城市里の小女人 提交于 2019-12-10 09:58:16
问题 Scenario: How to update a model? ASP MVC 6 I am trying to update a model. For passing the model information to the client(browser/app) I am using the DTO. Question 1: For updating, should I post the whole object back? Question 2: Is there a way I can easily pass only the information that is updated? If yes, how? Question 3: Can I use JSON Patch for updation? 回答1: Question 2: Is there a way I can easily pass only the information that is updated? If yes, how? Yes. You should create a view model

How to add COM references in ASP.NET mvc 6 and Visual Studio 2015?

℡╲_俬逩灬. 提交于 2019-12-10 09:38:56
问题 I can do that in Visual Studio 2012 w/o problems, but not in 2015 with MVC 6, pic related: Is it even possible? 回答1: I find your question interesting. DotNet application access to COM via interop assembly which can be generated with respect of tlbimp.exe for example. Typically you have already generated a lot of such intreops. You can see there in %SystemRoot%\assembly\GAC_MSIL directory. For example I have Office installed on my computer. I will show below how to create small ASP.NET 5

Is it possible/sensible to split ASP.Net Core 2 (.NET Framework) Web Api into Class Library and Hosting projects?

寵の児 提交于 2019-12-10 04:29:42
问题 I'm trying to port an existing WCF Web API (targeting .NET Framework 4.6.1) to ASP.Net Core 2 using Visual Studio 2017 (v15.4.5) and am having trouble figuring out good/common/supported ways to organize projects, and what types of project they should be. For example: Single project for Server and Hosting, or Class Library for Server and Console application for Hosting Windows Classic Desktop project for Console application and (new style csproj) Web Application for Server library, or both Web

How to access session from a view in ASP .NET Core MVC 1.0

此生再无相见时 提交于 2019-12-10 03:18:57
问题 I am trying to access session data from inside a view. Use Case: I'm storing status messages in the session that will be displayed at the top of the page. Currently I implemented this by using a DisplayMessages() function that sets some ViewData[....] properties and calling it at the beginning of every controller action. Goal: I want to only set the status message once without needing additional code in the controller to display the messages on the next page load. So I'm trying to access the

How to read a connectionString WITH PROVIDER in .NET Core?

强颜欢笑 提交于 2019-12-10 03:14:44
问题 I added .AddJsonFile("Connections.json", optional: true, reloadOnChange: true) in public Startup(IHostingEnvironment env) Connections.json contains: { "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=DATABASE;Trusted_Connection=True;MultipleActiveResultSets=true", "COR-W81-101": "Data Source=DATASOURCE;Initial Catalog=P61_CAFM_Basic;User Id=USERID;Password=PASSWORD;Persist Security Info=False;MultipleActiveResultSets=False;Packet Size=4096;", "COR-W81-100":

How to get the request URL on application startup

与世无争的帅哥 提交于 2019-12-10 03:00:58
问题 I'm trying to find the request URL (the domain specifically) when the application starts, in my Startup.cs file.. public Startup(IHostingEnvironment env) { Configuration = new Configuration().AddEnvironmentVariables(); string url = ""; } I need it in the Startup.cs file because it will determine what transient services are added later in the startup class, in the ConfigureServices method. What is the correct way of getting this information? 回答1: Sadly you are unable to retrieve the hosting