asp.net-core-mvc-2.0

ASP.NET Core CreatedAtRoute No route matches the supplied values

走远了吗. 提交于 2019-12-05 02:22:46
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/json")] [Route("api/page")] public class PageController : Controller { private IPageDataAccess

ASP .NET Core 2 MVC error NU1202 creating project on VS 2017 and NET CLI

给你一囗甜甜゛ 提交于 2019-12-04 06:35:30
I have installed VS2017 15.3.0 and .NET Core 2.0 and have created a default Web MVC application on VS 2017 and I got the following errors: Error NU1202 Package System.Threading.Overlapped 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Threading.Overlapped 4.0.1 supports: netstandard1.3 (.NETStandard,Version=v1.3) Error NU1202 Package System.IO.Compression 4.1.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.IO.Compression 4.1.0 supports: monoandroid10 (MonoAndroid,Version=v1.0) monotouch10 (MonoTouch,Version=v1.0) net45 (

ASP NET Core 2 with Full Framework

冷暖自知 提交于 2019-12-03 17:33:18
问题 I am unable to find any documentation, or examples, of an ASP.NET MVC Core app running under the full framework. It is supposed to be supported, but as I said I cannot find any documentation of how to configure a project for this, and have not been able to work it out myself. Has anyone got this working and can provide advice/sample on what needs to be done? 回答1: I am able to create/run ASP.NET Core 2.0 project with Full .NET framework 4.6.1, I followed below steps- Created new project using

ASP NET Core 2 with Full Framework

萝らか妹 提交于 2019-12-03 05:35:48
I am unable to find any documentation, or examples, of an ASP.NET MVC Core app running under the full framework. It is supposed to be supported, but as I said I cannot find any documentation of how to configure a project for this, and have not been able to work it out myself. Has anyone got this working and can provide advice/sample on what needs to be done? I am able to create/run ASP.NET Core 2.0 project with Full .NET framework 4.6.1, I followed below steps- Created new project using ASP.NET Core web application under Web category- On 2nd step, selected Web Application (Model-View

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

给你一囗甜甜゛ 提交于 2019-12-01 10:44:08
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 have infinite parents. Questions: How to set up routing template to achieve that? If the routing

Why is Razor Pages the recommended approach to create a Web UI in Asp.net Core 2.0?

痞子三分冷 提交于 2019-11-30 06:21:50
问题 Learning new things needs an investment of time, space and energy. I am currently learning Asp.Net Core MVC 2.0. This ASP.NET Core tutorials overview states: Razor Pages is the recommended approach to create a Web UI with ASP.NET Core 2.0. This information confused me in deciding whether I have to stop learning Asp.net Core MVC and start learning Asp.net Core Razor Pages. Why is Razor Pages the recommended approach to create a Web UI in Asp.net Core 2.0? Any directions are welcome. 回答1: Razor

Model binder for abstract class in asp.net core mvc 2

喜欢而已 提交于 2019-11-28 14:48:32
I've been trying to implement a model binder for an abstract class in ASP.NET Core 2 without success. I've studied two articles in particular which look very good: http://www.dotnetcurry.com/aspnet-mvc/1368/aspnet-core-mvc-custom-model-binding Asp net core rc2. Abstract class model binding There are two goals I'm trying to reach, Automatically create as many nested editors as needed from model (child nesting). Map the form values back into the model correctly. Here's my code based on the articles mentioned above. public class Trigger { public ActionBase Action { get; set; } } [ModelBinder

How to mock Session Object in asp net core

元气小坏坏 提交于 2019-11-28 09:18:50
问题 I am writing unit tests using moq framework. I am calling one method in base controller setsession() which will set session using SetString("userdata",object) and I have one more method getsession() which will get session. var sessionMock = new Mock<ISession>(); sessionMock.Setup(s => s.GetString("userdata")).Returns(Object);--failing sessionMock.Setup(s => s.SetString("userdata",object));--failing I am getting the error in s.GetString and s.SetString . As GetString and SetString are

How to unit test ViewComponent.Invoke()?

旧街凉风 提交于 2019-11-28 01:55:11
In ViewComponent object, HttpContext and User are read-only properties. How to unit test such a component? I'm using the MSTest Freamwork. The follow properties are used in my code Cookie Session User(System.Security.Principal) public ViewViewComponentResult Invoke() { var vm = new SummaryViewModel(); if (User.Identity is ClaimsIdentity identity && identity.IsAuthenticated) { vm.IsAuthenticated = true; vm.UserName = identity.Claims.FirstOrDefault(c => c.Type == "UserName").Value; vm.PhotoUrl = identity.Claims.FirstOrDefault(c => c.Type == "FacePicture").Value; } return View(vm); } [TestMethod]

Model binder for abstract class in asp.net core mvc 2

青春壹個敷衍的年華 提交于 2019-11-27 08:51:25
问题 I've been trying to implement a model binder for an abstract class in ASP.NET Core 2 without success. I've studied two articles in particular which look very good: http://www.dotnetcurry.com/aspnet-mvc/1368/aspnet-core-mvc-custom-model-binding Asp net core rc2. Abstract class model binding There are two goals I'm trying to reach, Automatically create as many nested editors as needed from model (child nesting). Map the form values back into the model correctly. Here's my code based on the