小编Yan*_*aya的帖子

如何允许覆盖 ASP.NET Core 应用程序中的 blob?

用户可以在创建记录时上传图像,当您编辑该记录并尝试上传新图像时,会出现“此 blob 已存在”错误。有没有办法可以在我的应用程序中启用同名 blob 的覆盖?

这是我处理更新过程的代码。

值得注意的是,为了应用程序,我创建了图像的三个迭代,因此我包含了包含该信息的数组。

CarController.cs

private readonly int[] sizeArray = new int[] { 700, 350, 150 };

[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(Car car)
{
    if (ModelState.IsValid)
    {
        //Create the Car
                _carService.InsertCar(car);

                //Get the ID of the newly created car
                int id = car.Id;

                //Define the container name for Azure Storage
                string strContainerName = "uploads";                               

                //Blob Client
                BlobServiceClient blobServiceClient = new BlobServiceClient(accessKey);
                BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(strContainerName);

                //Iterate over the array of image sizes
                foreach (var imageSize in sizeArray) …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-blob-storage asp.net-core

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

为什么我的 Azure Pipeline 作业失败并显示错误 NU1101?

我正在 Azure DevOps 中运行 CD/CI 管道,最近我的管道作业开始失败并出现以下错误:

##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
##[warning]Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.0 and 3.1) SDK/Runtime along with 2.1.
Unless you have locked down a SDK version for your project(s), 3.x SDK
might be picked up which might have breaking behavior as compared to
previous versions. 
Some commonly encountered changes are: 
If you're using `Publish` command with -o or --Output argument, you will …
Run Code Online (Sandbox Code Playgroud)

continuous-integration azure-devops asp.net-core azure-pipelines

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

包含日期的字符串上的 Linq 大于和小于运算符

我正在我的应用程序中编写一个 linq 查询,我想在其上使用“小于”运算符。然而,我尝试将其应用到的列是字符串类型(我们无法更改),并且导致智能感知抛出错误,因为“<”运算符不能在字符串类型上使用。

我的问题是我还能怎么做?这是我的代码中发生错误的部分。

public ActionResult Index()
{
    var results = Mapper.Map<IEnumerable<VesselViewModel>>(db.tbl_vessels
    .Where(p => 
          (p.vessel_type.Contains("AHTS")) &&
          (p.spotlist_id == 2) &&
          (p.fixture_start <= System.DateTime.Now.Date)
     )
    .ToList());
    return View(results);
}
Run Code Online (Sandbox Code Playgroud)

fixture_start是一个字符串,由于其他地方的复杂性,我们无法更改它。无论如何,这个问题有解决办法吗?

c# linq

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

如何在 Javascript 中向动态创建的输入字段添加唯一 ID?

我正在使用 javascript 动态创建输入字段,我的表单上允许有 10 个输入字段。为了确保将这些字段提交到正确的位置,我需要做的是为它们提供正确的 ID。我的问题是我该怎么做?

$(document).ready(function () {
    var max_fields = 10; //maximum input boxes allowed
    var wrapper = $(".input_fields_wrap"); //Fields wrapper
    var add_button = $(".add_field_button"); //Add button ID
    var x = 1; //initlal text box count

    var num = new Number;
    var newNum = num + 1;        

    /*if (x = max_fields) {
        alert("You can't add anymore fields.")   
    }
    */

    $(add_button).click(function (e) { //on add input button click
        e.preventDefault();
        if (x < max_fields) { //max input box allowed
            x++; …
Run Code Online (Sandbox Code Playgroud)

javascript jquery dynamically-generated

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

如何在 catch 异常中显示行号和帧?

我正在尝试将行号和帧写入文本文件,但无法使其工作。从我在网上读到的内容来看,我编写的方式应该可以工作,但它实际上并没有输出任何行号,使我的调试变得非常困难。任何人都可以帮忙指出我的代码可能有错误的地方吗?

catch (Exception e)
        {                
            var st = new StackTrace(e, true);
            var frame = st.GetFrame(0);
            var line = frame.GetFileLineNumber();
            var sw = new System.IO.StreamWriter(filename, true);

            sw.WriteLine(
                DateTime.Now.ToString() + "\r\n" 
                + e.Message + "\r\n" 
                + e.InnerException + "\r\n"                    
                + e.Source + "\r\n"
                + frame + "\r\n" 
                + line);
            sw.Close();

        }
Run Code Online (Sandbox Code Playgroud)

它确实输出一些信息,但不是行/帧号。

这是获取输出的示例。

22/08/2016 08:34:24
Input string was not in a correct format.
StringToNumber at offset 12099653 in file:line:column <filename unknown>:0:0 0
Run Code Online (Sandbox Code Playgroud)

另请注意,应用程序在“调试”而不是“发布”下运行。

c#

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

为什么我的复选框不将其值传递给 ASP.NET Core 中的控制器?

我觉得这可能是一个简单的解决办法,但我似乎无法绕过它。我有一个 ASP.NET Core Web 应用程序,我正在使用 ajax 表单将数据提交到我的控制器进行处理。我遇到的问题是我的复选框总是作为“false”传递,即使它们可能被选中。

我搜索了一些答案,但我尝试过的都没有成功。比如使用checked财产,确保名称正确。

任何人都可以阐明为什么当表单提交到控制器时这些值被忽略以及我如何修复它?

形式

<form asp-action="CreateCustomView" asp-controller="Data"
        data-ajax="true"
        data-ajax-method="POST">
        <div class="row">
            <div class="col">
                <div class="custom-control custom-checkbox">                            
                    <input type="checkbox" class="custom-control-input" id="ColName" name="ColName" checked>
                    <label class="custom-control-label" for="ColName">Name</label>
                </div>
            </div>

            <button type="reset">Reset</button>
            <button type="submit">Save changes</button>
</form>
Run Code Online (Sandbox Code Playgroud)

模型

namespace MyProject.Data
{
    public class GridView : BaseEntity
    {
        public string Name { get; set; }               
        public bool ColName { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

数据控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MyProject.Data;
using Microsoft.AspNetCore.Mvc; …
Run Code Online (Sandbox Code Playgroud)

c# model-view-controller asp.net-core

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

基金会5 - Joyride不工作

我正在努力让Joyride工作.我按照Zurb文档中的描述输入了代码,但它根本无法运行.我需要一些关于我可能做错的建议.

<div class="row">
  <div class="large-12 columns">
    <ul>
      <li><h2 id="firstStop" class="panel">First</h2></li>
      <li><h2 id="secondStop" class="panel">Second</h2></li   

    </ul>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

在我脚下的页面

<!-- At the bottom of your page but inside of the body tag --> 
    <ol class="joyride-list" data-joyride>
      <li data-id="firstStop" data-text="Next">
        <p>Test</p>
      </li>
      <li data-id="secondStop" data-text="Next">
        <p>Test</p>
      </li>
      <li data-button="End">
        <p>Test</p>
      </li>  
    </ol>
Run Code Online (Sandbox Code Playgroud)

并且基金会初始化为

$(document).foundation('joyride', 'start');
Run Code Online (Sandbox Code Playgroud)

但是,当我加载页面时没有任何反应.我现在感到困惑.谁能帮忙吗?

zurb-foundation zurb-joyride

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

为什么我的 EF 似乎从正在运行的 SQL 视图中返回重复的行?

我查过这个问题,但我发现没有任何东西对我有用。我在 SQL 中创建了一个视图,当您在 Management Studio 中运行它时该视图有效。当从我的 MVC 应用程序访问视图时,EF 返回相同的行而不是具有不同数据的行。

表:汽车

  • [ID]
  • [登记]
  • [制作]
  • [模型]

表:预订

  • [ID]
  • [预订开始日期]
  • [预订结束日期]
  • [车号]

查看:CarBookings

SELECT  [C].[Id],
        [C].[Registration],
        [C].[Make],
        [C].[Model],
        [B].[BookingStartDate],
        [B].[BookingEndDate]

FROM [Cars] AS C INNER JOIN [Bookings] AS B ON C.Id = B.CarId
Run Code Online (Sandbox Code Playgroud)

如果我在 SSMS 中运行查询,我会得到所有预期的结果,例如:

  • 汽车 1, 预订 12/03/2018
  • 汽车 1, 预订 19/09/2018

当我从我的 MVC 应用程序访问相同的视图时,我得到:

  • 汽车 1, 预订 12/03/2018
  • 汽车 1, 预订 12/03/2018

在控制器上放置一个断点表明结果是相同的,所以它不是导致它的表示层。没有应用过滤器,也没有任何条件。

我正在使用KendoUI并将结果返回到Grid.

这是我用于获取数据的控制器代码:

家庭控制器.cs

public ActionResult GetBookings([DataSourceRequest] DataSourceRequest request)
{
    var bookings = unitOfWork.BookingsRepository.Get(); …
Run Code Online (Sandbox Code Playgroud)

c# sql entity-framework

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

帮助解决 ASP.NET Core 3.1 应用程序中的“已有一个与此命令关联的打开的 DataReader 必须首先关闭”

我需要帮助修复错误消息:

已经有一个打开的 DataReader 与此命令关联,必须先将其关闭。

问题源于以下行:

foreach (var user in _userManager.Users) {
Run Code Online (Sandbox Code Playgroud)

我知道基本上,有另一个阅读器打开,另一个尚未关闭,但我不知道如何根据我的代码解决此问题。我四处寻找类似的问题,有很多,有些建议不添加跟踪,有些建议返回.ToList。我有点不知所措,需要一些帮助。

到目前为止,这是我的代码:

控制器

角色管理器和角色管理器都UserManager被注入,在本例中,我使用自己的 ApplicationUser 扩展了身份类。据我了解,在注入后,声明带有的项目_将不应用任何跟踪,这可能是错误的。

  private readonly RoleManager<IdentityRole> _roleManager;
  private readonly UserManager<ApplicationUser> _userManager;

  public AdministrationController(RoleManager<IdentityRole> roleManager,
         UserManager<ApplicationUser> userManager) 
  {
      _roleManager = roleManager;
      _userManager = userManager;
  }

[HttpGet]
public async Task<IActionResult> EditRole(string id)
{
    var role = await _roleManager.FindByIdAsync(id);

    if (role == null) {
        ViewBag.ErrorMessage = $"Role with Id = {id} cannot be found";
        return View("NotFound");
    }
    var model = new EditRoleViewModel
    { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net entity-framework-core asp.net-core

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

如何在我的 ASP.NET Core 应用程序中显示和更新我的自定义标识字段?

我使用它创建了一个 ASP.NET Core 应用程序,core 3.1并在其中包含了开箱即用的身份验证。我想添加一些自定义字段供我的用户完成,例如LocationInstagram。按照此处说明,我创建了一个ApplicationUser.cs模型,该模型继承IdentityUser并成功迁移了该模型以将字段添加到我的AspNetUsers表中。到目前为止一切正常。

我想将这些字段添加到我的用户帐户页面。我意识到我看不到用户帐户页面。使用以下说明,我将缺少的帐户页面添加到我的项目中。但是,当我添加缺少的字段时,它声称无法找到它们,尽管整个项目标识都ApplicationUser按照文档中的说明使用。

区域/页面/帐户/管理/Index.cshtml

@page
@model IndexModel
@{
    ViewData["Title"] = "Profile";
    ViewData["ActivePage"] = ManageNavPages.Index;
}

<h4>@ViewData["Title"]</h4>
<partial name="_StatusMessage" model="Model.StatusMessage" />
<div class="row">
    HEY
    <div class="col-md-6">
        <form id="profile-form" method="post">
            <div asp-validation-summary="All" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="Username"></label>
                <input asp-for="Username" class="form-control" disabled />
            </div>
            <div class="form-group">
                <label asp-for="Location"></label>
                <input asp-for="Location" class="form-control" />

            </div>
            <div class="form-group">
                <label asp-for="Instagram"></label>
                <input asp-for="Instagram" class="form-control" …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-core asp.net-core-identity

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

Chart.JS 全局选项

由于某种原因,我似乎在 Chart.JS 中遇到错误。它与您可以设置的全局选项有关。

如下 在此处输入图片说明 这是我的代码

var chart1 = document.getElementById("chart1").getContext("2d"),
chart2 = document.getElementById("chart2").getContext("2d"),
chart3 = document.getElementById("chart3").getContext("2d"),

datatest1 = document.getElementById("datatest1").value,
datatest2 = document.getElementById("datatest2").value,

color_bg = "#00b5e4",
color_fg = "#007799",

data1 = [{ value: Math.floor(Math.random() * 100), color: color_bg}, { value: Math.floor(Math.random() * 100), color: color_fg}],
data2 = [{ value: datatest1, color: color_bg}, { value: datatest2, color: color_fg}],
data3 = {
    labels: ["Jan", "Feb", "Mar"],
    datasets: [
        {
            fillColor: "rgba(220,220,220,0.5)",
            strokeColor: "rgba(220,220,220,0.8)",
            highlightFill: "rgba(220,220,220,0.75)",
            highlightStroke: "rgba(220,220,220,1)",
            data: [65, 59, 80, 81, 56, 55, …
Run Code Online (Sandbox Code Playgroud)

javascript variables global-variables chart.js

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