asp.net-core-mvc

How to Create Drop-Down-List from Database in (Asp.net Core - MVC)?

我只是一个虾纸丫 提交于 2020-12-15 04:38:04
问题 I have 2 models: News Model TypeOfNew Model with (one to many relationship), every (TypeOfNew) has one or multiple news. News Model: public class News { [Required(ErrorMessage = "ID إجباري.")] [Key] public int ID { get; set; } [Required(ErrorMessage = "الحقل إجباري.")] [Display(Name = "عنوان الخبر")] public string Title { get; set; } [Required(ErrorMessage = "الحقل إجباري.")] [Display(Name = "مصدر الخبر")] public string Source { get; set; } [Required(ErrorMessage = "الحقل إجباري.")] [Display

Reading connection string placed in ASP.NET Core from class library. Database First

只谈情不闲聊 提交于 2020-12-13 04:34:25
问题 The structure of projects looks like this: Cars (ASP.NET Core MVC. Here we have a connection string ) Cars.Persistence (ASP.NET Core Class library. Here we have Repository, Database First) I've created a Model by the following command from this msdn docs: Scaffold-DbContext "Server=PC\SQL2014XP;Database=Cars;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models So far so good. However, now carsContext has hard coded connection string in Cars.Persistence - ASP.NET

Reading connection string placed in ASP.NET Core from class library. Database First

人走茶凉 提交于 2020-12-13 04:34:25
问题 The structure of projects looks like this: Cars (ASP.NET Core MVC. Here we have a connection string ) Cars.Persistence (ASP.NET Core Class library. Here we have Repository, Database First) I've created a Model by the following command from this msdn docs: Scaffold-DbContext "Server=PC\SQL2014XP;Database=Cars;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models So far so good. However, now carsContext has hard coded connection string in Cars.Persistence - ASP.NET

XML Parsing Error: no root element found in ASP.NET Core 2.0 API

白昼怎懂夜的黑 提交于 2020-12-13 04:25:30
问题 I've encountered this problem, and I couldn't figure it out. I'm using ASP.NET Core 2 and Ajax. This is what the JavaScript debugger says: XML Parsing Error: no root element found Location: http://localhost:52617/api/favorites/ Line Number 1, Column 1: This is my JavaScript code: $(".js-toggle-fav").click(function (e) { function sendPost() { console.log("inside post send"); var button = $(e.target); $.ajax({ type: 'POST', url: "http://localhost:52617/api/Favorites/", data: {"EventId": @Model

XML Parsing Error: no root element found in ASP.NET Core 2.0 API

喜你入骨 提交于 2020-12-13 04:23:34
问题 I've encountered this problem, and I couldn't figure it out. I'm using ASP.NET Core 2 and Ajax. This is what the JavaScript debugger says: XML Parsing Error: no root element found Location: http://localhost:52617/api/favorites/ Line Number 1, Column 1: This is my JavaScript code: $(".js-toggle-fav").click(function (e) { function sendPost() { console.log("inside post send"); var button = $(e.target); $.ajax({ type: 'POST', url: "http://localhost:52617/api/Favorites/", data: {"EventId": @Model

How to extract state parameter from OpenIdConnect Token response in .Net Core MVC

▼魔方 西西 提交于 2020-12-12 12:00:27
问题 We are using Azure b2c to handle our logins on our .net core MVC site. We would like to use the optional state parameter to hold onto some data/a value between the initial request to the site (this value would likely be in a querystring param) which is then sent off to b2c to login, and the successfully logged in return back to the site. OpenIDConnect allow the setting of this state value in the request, and will pass it back with the token response. It appears that setting the value is

AuthorizeAttribute with Roles not working when migrating from MVC to Endpoint Routing in ASP.NET Core 3.1

六月ゝ 毕业季﹏ 提交于 2020-12-10 07:42:51
问题 I'm trying to upgrade my project from .UseMVC (asp.net core 2.2 compat style) to .UseEndpoint Routing and I'm getting re-directed to my suthentication failed page for all my requests. It has to do with the Claims - If I remove the role part of [Authorize(Roles = "Admin")] to simply [Authorize] then it works. It seems that it isn't picking up the claims that are assigned to the user. It seems to be a very similar issue as AuthorizeAttribute not working with Endpoint Routing in ASP.NET Core 3.1

aspnet-codegenerator: No code generators available, Even after adding Microsoft.VisualStudio.Web.CodeGeneration.Design

六月ゝ 毕业季﹏ 提交于 2020-12-08 13:37:41
问题 Unable to generate scaffolding using aspnet-codegenerator , below is what I tried: Created an ASP.Net RazorPages application using dotnet new webapp Did a dotnet build Installed dotnet-aspnet-codegenerator using dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4 Ran dotnet aspnet-codegenerator --help It says: No code generators are available in this project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference. Added the

aspnet-codegenerator: No code generators available, Even after adding Microsoft.VisualStudio.Web.CodeGeneration.Design

我是研究僧i 提交于 2020-12-08 13:27:31
问题 Unable to generate scaffolding using aspnet-codegenerator , below is what I tried: Created an ASP.Net RazorPages application using dotnet new webapp Did a dotnet build Installed dotnet-aspnet-codegenerator using dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4 Ran dotnet aspnet-codegenerator --help It says: No code generators are available in this project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference. Added the

Inject ApplicationUser in ASP.NET Core MVC

◇◆丶佛笑我妖孽 提交于 2020-12-08 07:29:24
问题 I have a class that requires ApplicationUser (from ASP.NET Identity). The instance should be the current user. public class SomeClass { public SomeClass(ApplicationUser user) { Currently, what I'm doing is I inject the current user from the Controller: var currentUser = await _userManager.GetUserAsync(User); var instance = new SomeClass(currentUser); Now I want to use Dependency Injection provided by Microsoft. I can't figure out how am I going to add ApplicationUser to the services. It