小编Wou*_*ter的帖子

使用#重定向到页面中的div

在控制器中处理了一些数据后,我想重定向到网页的某个div。他们有什么方法可以在网址末尾添加“#”吗?还是应该使用javascript处理它?

例:

[HttpPost]
public async Task<IActionResult> Edit(ViewModel model){
    ....
    return RedirectToAction("Info", new { id = model.Id, "#" = "item_55" });
}
Run Code Online (Sandbox Code Playgroud)

=>应该重定向到/ Info / id = 4#item_55

c# asp.net-core

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

asp.net核心中的web请求

我想在asp.net核心项目中做一个web请求.我尝试了以下但它似乎没有在请求中发送数据:

using System.Net;

...

//encoder
UTF8Encoding enc = new UTF8Encoding();

//data
string data = "[\"some.data\"]";

//Create request
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.Credentials = new NetworkCredential(user, secret);

//Set data in request
Stream dataStream = await request.GetRequestStreamAsync();
dataStream.Write(enc.GetBytes(data), 0, data.Length); 


//Get the response
WebResponse wr = await request.GetResponseAsync();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)

我没有收到错误,请求已发送,但它似乎没有发送带有请求的数据.我也无法用请求给出数据的长度.这是核心问题吗?(ps:凭证发送正确)

谁能帮我?

c# webrequest asp.net-core

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

使用 EntityFramework Core 时自动递增的值在 PostgreSQL 中不起作用

似乎 PostgreSQL 的自动增量功能似乎不起作用。

我有以下代码:

namespace project.Models
{
   public class DatabaseModel
   {
       [Key]
       [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
       [Column(Order=1, TypeName="integer")]
       public int ID { get; set; }
   }
 }
Run Code Online (Sandbox Code Playgroud)

当我更新数据库时(在执行迁移后),ID 列是主键而不是自动增量。

当我尝试向数据库添加新对象时,出现以下错误:

Microsoft.EntityFrameworkCore.DbContext[1]
  An exception occurred in the database while saving changes.
  Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> Npgsql.PostgresException: 23502: null value in column "ID" violates not-null constraint
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助解决这个问题吗?如何让密钥自动递增?

postgresql entity-framework-core asp.net-core

5
推荐指数
2
解决办法
8177
查看次数

控制台日志中的日期和时间

他们是在生产和开发环境的 asp.net core 2.0 项目的控制台日志中提及日期和时间的方法吗?

我的启动中有以下内容:

services.AddLogging(builder =>
{
            builder.AddConfiguration(Configuration.GetSection("Logging"+Environment.EnvironmentName))
                    .AddConsole()
                    .AddDebug();
});
Run Code Online (Sandbox Code Playgroud)

应用程序设置.json:

"LoggingDevelopment": {
    "IncludeScopes": false,
    "Console": {
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
      }
    }
  },
  "LoggingProduction": {
    "IncludeScopes": false,
    "Console": {
      "LogLevel": {
        "Default": "Error",
        "System": "Error",
        "Microsoft": "Error"
      }
    }
  },
Run Code Online (Sandbox Code Playgroud)

当前的[开发]日志布局(没有日志行的日期或时间):

info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action a.Controller (project) in 531.2457ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 532.5812ms 200 text/html; charset=utf-8
Run Code Online (Sandbox Code Playgroud)

在生产模式下,日期和时间对于错误行来说非常方便。

asp.net-core

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

使用 ef 在数据库中使用没有时间的日期

我应该使用什么类来保存带有 ef 和 asp.net 核心(使用数据库 postgres)的日期(没有时间)?DateTimeOffset 总是试图节省时间。

public class something
{
        [Column(TypeName="date")]
        [Required]
        public DateTimeOffset StartDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

postgresql entity-framework asp.net-core

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

获取控制器中的区域名称

他们是一种在控制器中获取区域名称的方法(以编程方式)吗?

以下似乎不起作用:

String currentArea = ControllerContext.RouteData.DataTokens["area"].ToString();
Run Code Online (Sandbox Code Playgroud)

asp.net-core

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