小编PKo*_*ant的帖子

C# Blazor 和数据绑定到 DateTime?

我必须为现有Asp.net Core 3.1 Blazor项目的日期和时间输入字段添加数据验证;这是我第一次与 Blazor 合作。

我在日期输入字段(具有日期选择器和绑定到日期时间变量的数据)上设置了数据绑定,没有任何问题。但是,时间输入的情况不同(它有一个时间选择器并绑定到另一个 DateTime 变量。)

简而言之,当用户使用时间选择器设置时间并将其关闭时,输入字段中的时间将返回到最初设置的时间。例如,如果时间输入当前设置为上午 12:00,然后用户从时间选择器中选择新时间(假设下午 2:00),则用户单击“确定”并关闭时间选择器,输入中的时间回到中午 12:00。我在同一页面上有另一个时间输入,但数据绑定到字符串而不是日期时间,如果在时间选择器中再次设置时间,则保留时间。

我写了一个很短的程序来演示这个问题。我的示例页面有三个输入字段:日期、时间和另一个时间,但其数据绑定到字符串。

在此输入图像描述

@page "/"

<h1>Hello, world!</h1>

Welcome to your new app.

<div class="wrapper">
  <section class="createevent">
    <EditForm EditContext="@_editContext" OnValidSubmit="@HandleValidSubmit" OnInvalidSubmit="@HandleInvalidSubmit">
      <DataAnnotationsValidator />
      <div class="form-group">
        <p>
          <label>
            Date:
          </label>
          <input id="txtDate" type="date" required @bind-value="_timeSample.date" />
          <ValidationMessage For="@(() => _timeSample.date)" />
        </p>
      </div>
      <div class="form-group">
        <p>
          <label>
            Time:
          </label>
          <input id="txtTime" type="time" required @bind="_timeSample.time" />
          <ValidationMessage For="@(() => _timeSample.time)" />
        </p>
      </div>
      <div class="form-group">
        <p>
          <label>
            Time2:
          </label>
          <InputText …
Run Code Online (Sandbox Code Playgroud)

c# blazor blazor-server-side blazor-client-side asp.net-blazor

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

如何从 .Net Core Web API 返回 Json?

这是一个基本问题。我是 ASP.Net Core 的新手,所以我使用 Visual Studio 2017 中的模板创建了一个 .Net Core Web API 项目,我想知道如何从 Get() 函数返回 Json 字符串。

提供了 Get() 函数。

    [HttpGet]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }
Run Code Online (Sandbox Code Playgroud)

我想知道如何更改,以便它返回如下所示的 int 变量的 Json 字符串。

    // GET: api/MOER
    [HttpGet]
    public <<some return type>> Get()
    {
        _MOER = 32;

        return <<return a Json result/string of _MOER>>;
    }
Run Code Online (Sandbox Code Playgroud)

我已经看到 Nuget 包 Newtonsoft.Json 在其中进行序列化/反序列化,但我不确定它是否适用于 .Net Core。

我也看到过使用 JsonResult 的例子,但是当我尝试使用这种方法时,编译器不知道 Json() 是什么。

    [HttpGet]
    public JsonResult Get()
    {
        _MOER = 32;

        return …
Run Code Online (Sandbox Code Playgroud)

c# json.net asp.net-core-webapi

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

Oracle ODAC 12c第3版32位测试版是否支持EF 6.x?

我在Visual Studio 2013中安装了Windows 8.1 64位.我安装了最新的Oracle ODAC 12c第3版32位测试版,声称支持EF 6.当我将ADO.NET实体框架添加到我的项目并选择我的Oracle时数据连接,它不允许我选择Entity Framework 6.0版本.它选择了Entity Framework 5.x,版本6.x显示为灰色.它表示"无法为您的数据连接找到与最新版本的实体框架兼容的实体框架数据库提供程序".这是为什么?

entity-framework odp.net

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

Durable Functions:如何将参数传递给 Orchestrator?

我是 Azure Durable 函数的新手,一直在关注“Azure Serverless Computing Cookbook”一书中的示例代码,但我被困住了,因为我的 Orchestrator 中的 .GetInput 函数返回 null。我的 Blob 触发器将文件名作为参数传递给我的 Orchestrator。我认为它调用了错误的重载函数,但不确定如何调用正确的函数。

await starter.StartNewAsync("CSVImport_Orchestrator", name); 
Run Code Online (Sandbox Code Playgroud)
        [FunctionName("CSVImport_Orchestrator")]
        public static async Task<List<string>> RunOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            var outputs = new List<string>();
            string CSVFileName = context.GetInput<string>(); //<<== returns null???
            {
                List<Employee> employees = await context.CallActivityAsync<List<Employee>>("ReadCSV_AT", CSVFileName);
            }
            return outputs;
        }

        [FunctionName("CSVImportBlobTrigger")]
        public static async  void Run([BlobTrigger("import-obiee-report/{name}", Connection = "StorageConnection")]Stream myBlob, string name, [DurableClient]IDurableOrchestrationClient starter, ILogger log)
        {
            string instanceId = await starter.StartNewAsync("CSVImport_Orchestrator", name); 
            log.LogInformation($"C# Blob trigger function Processed …
Run Code Online (Sandbox Code Playgroud)

c# azure-durable-functions

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

使用异步/等待时我的控制台应用程序过早关闭?

我有一个控制台应用程序,它所做的就是循环所有客户并向特定客户发送电子邮件,然后关闭。我注意到 MailKit\xe2\x80\x99s 中的一些函数提供异步功能,因此我尝试使用它们而不是非 aysnc,当我这样做时,它执行了第一个语句 (emailClient.ConnectAsync),然后我注意到我的控制台应用程序正在关闭。它没有\xe2\x80\x99t崩溃。在调用 SendReports() 函数后,执行返回到 Main() 并继续执行。

\n\n
private static void Main(string[] args)\n{\n  ...\n  var reportServices = new ReportsServices();\n\n  reportServices.SendReportsToCustomers();\n\n  Log.CloseAndFlush();  // It executes the first await call then returns here.\n}\n\ninternal class ReportsServices\n{\n  public async void SendReportsToCustomers()\n  {\n    try\n    {\n      foreach (var customer in _dbContext.Customer)\n      {\n          ...\n          await SendReport(customer.Id, repTypeId, freqName);\n      }\n    }\n    catch (Exception e)\n    {\n      Console.WriteLine(e);\n      throw;\n    }\n  }\n\n  private async Task SendReport(int customerId, int repTypeId, string freqName)\n  {\n    try\n    {\n      ...\n        var es = new …
Run Code Online (Sandbox Code Playgroud)

c# multithreading mailkit

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