asp.net-core-mvc

Routing in MVC 6

我与影子孤独终老i 提交于 2019-12-01 04:58:31
问题 I have a super simple controller with 2 methods: public IActionResult Users(long id) { return Json(new { name = "Example User" }); } public IActionResult Users() { return Json(new { list = new List<User>() }); } One to select all users and the other to return all users. In web api 2 I could user the following route and everything worked fine: config.Routes.MapHttpRoute( name: "Users", routeTemplate: "v1/Users", defaults: new { action = "Users", controller = "Users" }, constraints: null,

Migrate html helpers to ASP.NET Core

て烟熏妆下的殇ゞ 提交于 2019-12-01 04:51:44
问题 I'm converting a project to ASP.NET Core. I need to migrate lots of reusable html helpers, but html helpers do not exist in Core. Some are complex, some simple. Here's a extremely simple example: @helper EditIcon() { <i class="glyphicon glyphicon-pencil"></i> } Note that this is only an example. Point is writing a tag helper for that is gigantic overkill. Same for partials. Same for view components. We're talking about a little snippet of Razor. What is my best option? 回答1: So, seems there

Override Default Identity Table Names

南楼画角 提交于 2019-12-01 04:48:27
问题 I would like to rename the default identity table names: AspNetRoles AspNetUserClaims AspNetUserLogins AspNetUserRoles AspNetUsers I understand how to do this using EF6: protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<IdentityUser>() .ToTable("Users", "dbo").Property(p => p.Id).HasColumnName("User_Id"); modelBuilder.Entity<User>() .ToTable("Users", "dbo").Property(p => p.Id).HasColumnName("User

Angular JS MVC Web API Model/ Parameter not binding .NET Core

假如想象 提交于 2019-12-01 04:43:14
I am using Angular JS with TypeScript and ASP.NET Core MVC/API. I have an apiService which deals with all POST and GET requests to the server, which looks like this: module TBApp { export class apiService { static $inject = ['$http', 'notificationService']; constructor(private $http, private notificationService: notificationService) { } get(url, config, success, failure) { return this.$http.get(url, config) .then(result => { this.handleResponse(result, success); }, result => { this.handleError(result, failure) }); } post(url, data, success, failure) { return this.$http.post(url,data) .then

Request BinaryRead in ASP.NET 5 (MVC6)

ε祈祈猫儿з 提交于 2019-12-01 04:38:19
问题 I had this code working in ASP.NET MVC 5, but I can't make it works in ASP.NET MVC 6 (ASP.NET 5) Can someone help me? public EmptyResult PayPalPaymentNotification(PayPalCheckoutInfo payPalCheckoutInfo) { PayPalListenerModel model = new PayPalListenerModel(); model._PayPalCheckoutInfo = payPalCheckoutInfo; byte[] parameters = Request.BinaryRead(Request.ContentLength); if (parameters != null) { model.GetStatus(parameters); } return new EmptyResult(); } The error is in: byte[] parameters =

Loading of references in EF7

馋奶兔 提交于 2019-12-01 04:37:43
I'm having two classes - author and blogpost: public class Author { public Author() { Blogposts = new HashSet<Blogpost>(); } public int Id { get; set; } public string Name { get; set; } public virtual ICollection<Blogpost> Blogposts { get; set; } } and public class Blogpost { public Blogpost() { } // Properties public int Id { get; set; } public string Text { get; set; } public int AuthorId { get; set; } public Author Author { get; set; } } Using EF7 (beta4), I'm connecting them the following way: public partial class MyDbContext : DbContext { public virtual DbSet<Author> Author { get; set; }

Getting blank pages for error messages with UseDeveloperExceptionPage enabled

非 Y 不嫁゛ 提交于 2019-12-01 04:35:58
I'm getting blank pages for both when I enter an invalid URL, or when an exception is thrown within my application. I have UseDeveloperExceptionPage() enabled, and I have confirmed that my app environment is in development mode, and that the method is firing. The app works fine, but not having error messages displaying in the browser is frustrating. My Startup.cs Configure method: public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseIISPlatformHandler(); app.UseStaticFiles(); app.UseIdentity(); app.UseMvc(m => m.MapRoute( name: "default", template: "{controller}/

How to set the request timeout for one controller action on IIS and IIS Express

允我心安 提交于 2019-12-01 04:33:52
I need to increase the request timeout for a specific controller action in my application programmatically in the controller. The best way I have found so far to handle a long running script (if your application simply can't avoid having one) is to firstly create an async handler: public async Task<IActionResult> About() { var cts = new CancellationTokenSource(); cts.CancelAfter(180000); await Task.Delay(150000, cts.Token); return View(); } In the snippet above I have added a Cancellation token to say that my Async Method should cancel after 180 seconds (even though in this example it will

Entity Framework Core doesn't validate data when saving?

∥☆過路亽.° 提交于 2019-12-01 04:32:32
问题 I have the following remote validation rule: [AcceptVerbs("Get", "Post")] public IActionResult ValidateWindowEndDate(DateTime? endDate, DateTime? startDate) { int minWeeks = 8; if (startDate.HasValue && endDate.HasValue && (endDate < startDate.Value.AddDays(minWeeks * 7))) { return Json(data: $"Inspection window end date must be at least {minWeeks} weeks after start date."); } return Json(data: true); } That's linked to a property in my class as follows: [Required] [Remote(

how to include views in asp.net 5 class library nuget package

余生长醉 提交于 2019-12-01 04:26:13
I'm creating a class library project that will contain some ViewComponents. It is nice that VS 2015 can automatically produce the NuGet package for me, but is there any way that I can make it include content files like .cshtml view files that my ViewComponents will need? Previously I've done packaging with batch files and nuspec files to make it include content, will I have to continue that approach or is there a way to tell VS 2015 about content files to include? Not doable as yet. The feature will be in beta7 来源: https://stackoverflow.com/questions/31412210/how-to-include-views-in-asp-net-5