asp.net-core-mvc

Equivalent of “@section” in ASP.NET Core MVC?

北城余情 提交于 2019-12-22 01:44:55
问题 In the default _Layout.cshtml file, scripts are defined in "environment"s like so: <environment names="Development"> <script src="~/lib/jquery/dist/jquery.js"></script> <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script> <script src="~/js/site.js" asp-append-version="true"></script> </environment> <environment names="Staging,Production"> <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js" asp-fallback-src="~/lib/jquery/dist/jquery.min.js" asp-fallback-test=

ASP.NET Core MVC model property binding is null

只谈情不闲聊 提交于 2019-12-22 01:29:24
问题 I am using ASP.NET Core RC2 MVC with Entity Framework and trying to save a new car. The problem is, that in the create method of the car controller the property Color is null when the action is posted back. All other properties/fields are set. But the Color which refers to the CarColors model is null. The CarColor model public class CarColor { [Key] public int CarColorId { get; set; } [MinLength(3)] public string Name { get; set; } [Required] public string ColorCode { get; set; } } The main

Is there any replace of AssemblyBuilder.DefineDynamicAssembly in .NET Core?

做~自己de王妃 提交于 2019-12-22 01:12:13
问题 How to port the following code to .Net Core: AppDomain.CurrentDomain.DefineDynamicAssembly( new AssemblyName( Guid.NewGuid().ToString()), AssemblyBuilderAccess.RunAndSave); Is it possible? 回答1: add this to your project.json "dependencies": { "System.Reflection.Emit": "4.0.1" }, and use AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()), AssemblyBuilderAccess.Run); AssemblyBuilderAccess.RunAndSave is not supported at the moment link to souce. Update: For new

Custom 404 response model

主宰稳场 提交于 2019-12-22 00:25:35
问题 I want to provide a custom reponse for all 404s on our API. For example: { "message": "The requested resource does not exist. Please visit our documentation.." } I believe the following result filter works for all cases within the MVC pipeline: public class NotFoundResultFilter : ResultFilterAttribute { public override void OnResultExecuting(ResultExecutingContext context) { var result = context.Result as NotFoundResult; if (result != null) { context.Result = new HttpNotFoundResult(); // My

ASP.NET MVC 6 using IIS to develop without publish

心不动则不痛 提交于 2019-12-21 22:18:44
问题 Is there any way to develop an ASP.NET MVC 6 beta 8 application on IIS without having the need to publish the application? After install the httpPlatform module I am able to point IIS to a published application. But how can yo point IIS to say your visual studio solution wwwroot so you can develop and see the changes you make without having the need to publish? Is this no longer possible like how it you could develop asp.net MVC 5 apps? For development is IIS Express and Kestrel the preferred

How to validate JWT during websocket request. .net core

冷暖自知 提交于 2019-12-21 21:31:46
问题 I am working on a small .net core app that uses JWT authentication and websockets. I have succesfully implemented generating and validating tokens for standard web api controllers. However I also want to validate the token for a WebSocket request which of course won't work with the [Authorize] attribute. I have setup my middleware pipeline like this: app.UseWebSockets(); app.Use(async (http, next) => { if (http.WebSockets.IsWebSocketRequest == false) { await next(); return; } /// Handle

How to run dynamic SQL query in Entity Framework 7 that auto-maps to Entities (SqlQuery<T>)?

柔情痞子 提交于 2019-12-21 20:09:20
问题 I have an existing app that I am trying to upgrade from MVC5/EF6 to MVC6/EF7. We dynamically create some of our SQL tables, and as a result, have made use of the System.Data.Entity.Database.SqlQuery method to automatically map to entities that we use throughout our application. This method seems to have gone away (i.e. not part of Microsoft.Data.Entity.Infrastructure.Database ) in EF7 (or is not yet implemented). Are there plans to re-implement this method in EF7 or is there another way to

Should my custom ASP.Net 5 MVC 6 Tag Helpers have an asp- prefix?

好久不见. 提交于 2019-12-21 14:06:12
问题 I've been reading about the new support for Tag Helpers in MVC 6 and now need to create my own. I see that the built in tag helpers for existing HTML elements are all prefixed with "asp-" For example: <a asp-controller="Home" asp-action="Index">Home</a> But what about my own custom tag helpers. Should I also prefix those with "asp-" to show that it is running on the server. Or should this be reserved for framework attributes? Should I create my own project/company named prefix instead? Is

MVC 6 change return content-type

╄→гoц情女王★ 提交于 2019-12-21 13:26:15
问题 I seem to be unable to change the return content-type of my controller-method in the new Asp.net MVC 6. I tried various variations on: Context.Response.Headers.Add("Content-type", "text/x-vcard"); In the old WebApi days I could use this, and change the formatter: return Request.CreateResponse(HttpStatusCode.OK, data, JsonMediaTypeFormatter.DefaultMediaType); Could I do something similar in MVC 6? 回答1: You can do that by setting the Produces("ResultType") attribute on the controller action.

VS 2015 CTP 6 Nuget Package Source

本秂侑毒 提交于 2019-12-21 12:28:08
问题 After installing VS 2015 CTP 6 it added the following url to Available Package Sources: https://api.nuget.org/v3/index.json and turned off the following: https://www.nuget.org/api/v2/ When it did this it stopped downloading all nuget packages. I switched it back to the old one and everything is working again. One thing I noticed is that the old feed is xml and the new one is json. NOTE: I did upgrade the Nuget Package Manager after installing VS 2015 CTP 6. Is anyone else having this issue?