小编Gug*_*dua的帖子

ModelState 错误:值“null”对于可为空的字段无效

ModelState 会抛出错误,因为可空字段为空。

我有一个模型:

public class PersonModel
{
    public int? ID { get; set; }

    [Required]
    [StringLength(256)]
    public string Title { get; set; }

    [Required]
    [StringLength(256)]
    public string Name { get; set; }

    [Required]
    [StringLength(256)]
    public string Lastname { get; set; }

    [StringLength(1024)]
    public string Description { get; set; }

    public int? OrganizationID { get; set; }

    public string Organization { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

控制器:

var errors = ModelState.Where (c => c.Value.Errors.Count > 0).Select (c => c.Value).ToList ();

if (!errors.Any …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-core

7
推荐指数
1
解决办法
6459
查看次数

无法访问hangfire 仪表板

当我尝试访问 localhost:5000/hangfire 时,我被重定向到错误页面(我有一个返回相对状态页面(400,404 等)的控制器)

这是我收到的错误:在此输入图像描述

我想 /hangfire 不存在。它所指的“HandeErrorCode”来自我的控制器。

[Route ("Error/{statusCode}")]
        public IActionResult HandleErrorCode (int statusCode) {
            var statusCodeData = 
HttpContext.Features.Get<IStatusCodeReExecuteFeature> ();

        switch (statusCode) {
            case 404:
                return View("Status404");
            case 401:
                return View("Status401");
            case 400:
                return View("Status400");    
            case 500:
                return View("Status500");
        }

        return View ();
    }
Run Code Online (Sandbox Code Playgroud)

启动.cs

配置服务

services.AddHangfire(configuration=>{
              configuration.UsePostgreSqlStorage(connectionString);
          }); 
Run Code Online (Sandbox Code Playgroud)

配置

app.UseHangfireDashboard("/hangfire");    
      app.UseHangfireServer();
Run Code Online (Sandbox Code Playgroud)

编辑:整个 Startup.cs

public class Startup {
public Startup (IHostingEnvironment env) {

  Console.WriteLine ("startin app {0}, which uses env {1} and has root {2}", env.ApplicationName, env.EnvironmentName, env.ContentRootPath);
  Configuration …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

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

我如何每秒调用谷歌脚本触发器?

现实生活中的问题是,我想每 X 秒调用一次 api,但似乎无法使用 Google 脚本来完成它。

据我所知,您可以每隔 1、5、10、15 或 30 分钟调用一次触发器。有没有办法每秒运行 Google 脚本?

  function createTimeDrivenTriggers() {
  ScriptApp.newTrigger('myFunction')
      .timeBased()
      .everyMinutes(1) //I can not write 0.01 instead of 1 here. 
      .create();
}

function myFunction() {
  Logger.log("Logging");
}

createTimeDrivenTriggers();
Run Code Online (Sandbox Code Playgroud)

triggers google-apps-script

4
推荐指数
1
解决办法
5287
查看次数

SelectPDF .Net Core 2.2:异常:转换失败。无法加载共享库“kernel32.dll”或其依赖项之一

我正在尝试实现SelectPdf。我正在 OS X 上工作,我认为这就是我遇到这个问题的原因:

异常:转换失败。无法加载共享库“kernel32.dll”或其依赖项之一。为了帮助诊断加载问题,请考虑设置 DYLD_PRINT_LIBRARIES 环境变量: dlopen(libkernel32.dll, 1): image not find

macOS 有替代方法吗?

c# asp.net-core

3
推荐指数
1
解决办法
3926
查看次数

InvalidCastException:无法将“System.DBNull”类型的对象转换为“System.Nullable`1[System.Int32]”

我正在尝试从数据库执行存储过程。但是,我遇到了一个例外:

InvalidCastException:无法将“System.DBNull”类型的对象转换为“System.Nullable`1[System.Int32]”类型。

“results.Add”行抛出异常。

var result = new List<GetActiveUserPackagesForOpenBillingPeriodResult> ();

using (var conn = new NpgsqlConnection ("Host=localhost;Port=xxx;Database=xxx;Username=postgres;Password=xxx;TrustServerCertificate=true;ApplicationName=xxx;")) {
    using (var cmd = new NpgsqlCommand ("\"GetActiveUserPackagesForOpenBillingPeriod\"", conn)) {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue ("somedate", DateTime.Today);
        conn.Open ();

        var reader = cmd.ExecuteReader ();

        string x = DBNull.Value.Equals (reader) ? " " : reader.ToString ();

        if (x != null) 
        {
            while (reader.Read ()) {

                result.Add (
                    new GetActiveUserPackagesForOpenBillingPeriodResult {
                        Amount = (decimal) reader["Amount"],
                            AcceptanceActID = (int?) reader["AcceptanceActID"],
                            PackageID = (int) reader["PackageID"],
                            UserID = (int) reader["UserID"], …
Run Code Online (Sandbox Code Playgroud)

c# sql postgresql asp.net-core

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

如何在 .cshtml 中显示 SVG

我正在尝试在 .cshtml 页面上显示 .svg 图像。

\n\n

Status404.cshtml

\n\n
@inject Context Session\n@{\n    Layout = "";    \n\n}\n\n<img src="/workspace/src/Application/wwwroot/img/404.svg" alt="404page"/>\n\n@if(Session.CurrentUser.Language=="ka"){\n    <p><\xe1\x83\xa5\xe1\x83\x90\xe1\x83\xa0\xe1\x83\x97\xe1\x83\xa3\xe1\x83\x9a\xe1\x83\x98 \xe1\x83\xa2\xe1\x83\x94\xe1\x83\xa5\xe1\x83\xa1\xe1\x83\xa2\xe1\x83\x98</p>\n}\n\n@if(Session.CurrentUser.Language=="en"){\n    <p><ENG TEXT HERE</p>\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

结果:

\n\n

结果

\n\n

我尝试创建一个像 404Partial.cshtml 这样的部分视图(将 .svg 重命名为 .cshtml),然后将其包含在 .cshtml 中,如下所示:

\n\n
@await Html.PartialAsync("/workspace/src/Application/Views/404Partial.cshtml");\n
Run Code Online (Sandbox Code Playgroud)\n\n

但它找不到视图。

\n

razor asp.net-core

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