asp.net-core-mvc

Creating a ModelBinder for MongoDB ObjectId on Asp.Net Core

落花浮王杯 提交于 2019-12-10 14:31:40
问题 I'm trying to create a very simple model binder for ObjectId types in my models but can't seem to make it work so far. Here's the model binder: public class ObjectIdModelBinder : IModelBinder { public Task BindModelAsync(ModelBindingContext bindingContext) { var result = bindingContext.ValueProvider.GetValue(bindingContext.FieldName); return Task.FromResult(new ObjectId(result.FirstValue)); } } This is the ModelBinderProvider I've coded: public class ObjectIdModelBinderProvider :

ASP.NET vNext - MissingMethodException: Method not found: Microsoft.CodeAnalysis.Diagnostic> EmitResult.get_Diagnostics()'

大城市里の小女人 提交于 2019-12-10 14:14:25
问题 I upgraded this morning to VS2015 RC, and I created a new project using the ASP.NET 5 Template - Web Site. I have an error that I am not able to solve: An unhandled exception occurred while processing the request. MissingMethodException: Method not found: 'System .Collections.Immutable.ImmutableArray`1 Microsoft.CodeAnalysis.Emit.EmitResult.get_Diagnostics()'. Microsoft.AspNet.Mvc.Razor.RoslynCompilationService.Compile(RelativeFileInfo fileInfo, String compilationContent) Here is the full

ASP.NET Core MVC Attribute Routing Inheritance

*爱你&永不变心* 提交于 2019-12-10 13:24:38
问题 I always used this approach in my MVC applications before [Route("admin")] public class AdminController : Controller { } [Route("products")] public class ProductsAdminController :AdminController { [Route("list")] public IActionResult Index() { ... } } Url.RouteUrl() for Index action returned /admin/products/list/ Now in .NET Core it ignores base class route attribute and result is just /products/list/ Is this new to .NET Core? Is there any setup so system can combine action + controller +

ASP NET Core 2.0 appsettings.Development.json not working with logging configuration

有些话、适合烂在心里 提交于 2019-12-10 13:02:07
问题 I have installed VS2017 15.3.0 Preview 4 and .NET Core 2.0 Preview 2 and have created a default Web MVC application. I am interested in seeing how the new logging functionality works but I cannot get VS to use the logging values defined in appsettings.Development.json when viewing the Debug output window. My understanding is that the appsettings.Development.json file takes precedence over the appsettings.json yet only values in the latter file has any effect on the debug window. Is this right

Model Binding Issue with ASP.NET5 MVC6

北战南征 提交于 2019-12-10 12:46:57
问题 Im trying to post some JSON data on an angular form to my ASP.NET5 MVC6 Controller action. The model binder does not seem to be working. Not sure what I'm missing here. My ASP Controller: public class DefaultController : Controller { public IActionResult Index() { return View(); } [HttpPost] public IActionResult SubmitTest(QTestViewModel model) { return Json("true"); } } My Angular Controller: angular.module("testActiveMq", []) .controller("MqTestController", ["$scope", "$http", function (

How to get the Values from a Task<IActionResult> returned through an API for Unit Testing

北慕城南 提交于 2019-12-10 12:37:40
问题 I have created an API using ASP.NET MVC Core v2.1. One of my HttpGet methods is set up as follows: public async Task<IActionResult> GetConfiguration([FromRoute] int? id) { try { if (!ModelState.IsValid) { return BadRequest(ModelState); } ..... // Some code here return Ok(configuration); } catch (Exception ex) { ... // Some code here } } When unit testing this I can check that Ok was the response, but I really need to see the values of the configuration. I don't seem to be able to get this to

How to get JQuery-UI to work with ASP.NET MVC6?

夙愿已清 提交于 2019-12-10 12:19:32
问题 I have just started with MVC6 (RC), have created a project based on the standard template to MVC6 RC and desperately try to bring JQuery-UI to work. I have overtaken the following example from the JQuery-UI page in one of my views: <script> $(function() { var availableTags = [ "ActionScript", "AppleScript", "Asp", "BASIC", "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang", "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp", "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme"]; $

Cannot add Scaffold > MVC Controller with views, using Entity Framework in Asp.NET Core

我怕爱的太早我们不能终老 提交于 2019-12-10 12:15:35
问题 When I try to add Controller using build-in generator I get following error message: Where "Brand" is a model class and "ApplicationDbContext" is my data context class. I never encoutered error like this before. It does not occur all the time (2 success vs 30-40 attempts without changing single line of code). I was able to create Controller for same class minutes ago, but it's really annoying when you try to add something new and try more than 10 times with no results. Of course, I could

Duplicate type name within an assembly in Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware

て烟熏妆下的殇ゞ 提交于 2019-12-10 12:12:54
问题 I have .NET Core 1.1 API and i am handling the error in startup.cs as below. I am using Serilog public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime, IRequestContext requestContext) { loggerFactory.AddSerilog(); // Ensure any buffered events are sent at shutdown appLifetime.ApplicationStopped.Register(Log.CloseAndFlush); var logger = loggerFactory.CreateLogger<Startup>(); app.UseExceptionHandler( options => {

How to use buttons in Asp.Net to call a method

China☆狼群 提交于 2019-12-10 11:31:28
问题 I am trying to make a button in my View call a method in the Model using the button's onClick event, but I am not sure how to make this work. The button just doesn't do anything. This is my View: <html> <body> <div> <p>Coins: @Model.Coins</p> <button type="button" id="btnScore" onclick="Btn_Click">Click me!</button> </div> </body> </html> This is the model I try to call the method in: public class ClickerGame { public int Coins { get; set; } public ClickerGame() { Coins = 0; } public void Btn