小编The*_*t11的帖子

14
推荐指数
1
解决办法
2095
查看次数

ASP.Net Core 2.0 - 引用'Microsoft.NET.Sdk.Web'和'PreserveCompilationContext'属性未设置为false

我在_ViewImports.cshtml文件中收到以下错误.

One or more compilation references are missing. Ensure that your project is referencing 'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false.

堆栈跟踪:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
      An unhandled exception has occurred while executing the request
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
C:\src\LunchVoting\Web\Views\_ViewImports.cshtml(1,7): error CS0246: The type or namespace name 'LunchVoting' could not be found (are you missing a using directive or an assembly reference?)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(RazorCodeDocument codeDocument, String generatedCode)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(String relativePath)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CreateCacheEntry(String normalizedPath)
--- …
Run Code Online (Sandbox Code Playgroud)

asp.net-core-mvc asp.net-core asp.net-core-2.0

13
推荐指数
1
解决办法
1万
查看次数

Typescript - 使用泛型进行本地存储

我正在使用以下代码集并使用本地存储获取强类型项目。

该集按预期工作并将 JSON 放入本地存储中。

但是,当取出相同的项目时,转换为通用类型似乎不起作用。它不会引发异常,只是返回 JSON 字符串,而不是所需的类型化对象。

export class StorageService {
    constructor() { }

    setItem<T>(key: string, item: T): void {
        localStorage.setItem(key, JSON.stringify(item));
    }

    getItem<T>(key: string): T {
        let data: any = localStorage.getItem(key);
        if (!data) return null;

        let obj: T;

        try {
            obj = <T>JSON.parse(data);
        } catch  (error) {
            obj = null;
        }

        return obj
    }
}
Run Code Online (Sandbox Code Playgroud)

generics local-storage typescript

8
推荐指数
2
解决办法
1万
查看次数

是否可以使用 IComparable 来比较实体框架中的实体?

我有一个 POCO 类,它实现了IComparable.

public interface IEntity : IComparable
{
    long Id { get; set; }

    Func<IEntity, bool> CompareFunction { get; }
}

public abstract class BaseEntity : IEntity
{
    public virtual long Id { get; set; }

    public Func<IEntity, bool> CompareFunction
    {
        get
        {
            Func<IEntity, bool> compare = EvaluateEquivalency;
            return compare;
        }
    }

    public static int Compare(BaseEntity left, BaseEntity right)
    {
        if (object.ReferenceEquals(left, right))
        {
            return 0;
        }

        if (object.ReferenceEquals(left, null))
        {
            return -1;
        }

        return left.CompareTo(right);
    } …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework

6
推荐指数
1
解决办法
6646
查看次数

Angular HTTP Interceptor - 在多模块应用程序中显示微调器

我正在尝试显示ng4-loading-spinner对我的API进行HTTP调用的微调器.

我的代码基于以下链接中的示例:

我的Angular 5应用程序有多个多个模块.HTTP拦截器位于"服务"模块中.

我认为我有一个依赖注入问题,因为当我使用Chrome Dev Tools调试代码时,代码HTTP拦截器代码无法执行.

API-interceptor.ts

import 'rxjs/add/operator/do';
import 'rxjs/add/operator/catch'
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import {
    HttpEvent,
    HttpInterceptor,
    HttpHandler,
    HttpRequest,
    HttpResponse
} from '@angular/common/http';
import { Ng4LoadingSpinnerService } from 'ng4-loading-spinner';

@Injectable()
export class ApiInterceptor implements HttpInterceptor {

    private count: number = 0;

    constructor(private spinner: Ng4LoadingSpinnerService) { }

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        this.count++;

        if (this.count == 1) this.spinner.show();

        let handleObs: Observable<HttpEvent<any>> = next.handle(req);

        handleObs
            .catch((err: …
Run Code Online (Sandbox Code Playgroud)

angular-http-interceptors angular angular5

6
推荐指数
1
解决办法
8508
查看次数

Angular CLI 6 - 使用源映射构建角度库

我有一个使用Angular CLI 6(6.08)生成的Angular 6项目.

我使用ng generate library [lib name] --prefix [lib prefix](本文中概述的方法:https://medium.com/@tomsu/how-to-build-a-library-for-angular-apps-4f9b38b0ed11)创建了单独的库.

我使用构建每个库ng build [lib name],然后使用我的应用程序ng serve.

但是,当我在Chrome开发工具中查看源代码时,我的库没有源映射.

我已经尝试使用ng build [lib name] --source-map(如此处指定的:https://github.com/angular/angular-cli/wiki/build)构建每个库,但我认为这仅用于构建该应用程序,而不是库.

有谁知道我做错了有另一种解决方案吗?

angular-cli angular6 angular-cli-v6

6
推荐指数
3
解决办法
3518
查看次数

ASP.Net Core验证问题状态-绑定验证未返回问题详细信息

同样的问题在这里发布:https : //github.com/aspnet/Mvc/issues/8564

我遇到一个问题,当执行命中控制器时,我的代码显式返回ValidationProblemDetails响应。

但是,当绑定验证阻止执行到达控制器时,我得到以下JSON响应(标准模型状态验证对象)。

{
  "Email": [
    "Invalid email address"
  ]
}
Run Code Online (Sandbox Code Playgroud)

为什么它不返回响应中的验证问题详细信息?

我正在使用Microsoft.AspNetCore.App2.1.4软件包。

请求模型

public class RegistrationRequest
{
    [Description("Given Name")]
    [MaxLength(100)]
    [Required(ErrorMessage = "Given Name is required")]
    public string GivenName { get; set; }

    [MaxLength(100)]
    [Required(ErrorMessage = "Surname is required")]
    public string Surname { get; set; }

    [MaxLength(255)]
    [Required(ErrorMessage = "Email is required")]
    [EmailAddress(ErrorMessage = "Invalid email address")]
    public string Email { get; set; }

    [Required(ErrorMessage = "Password is required")]
    public string Password { get; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-2.1

5
推荐指数
1
解决办法
1872
查看次数