小编Eri*_*ips的帖子

将 [0-9] 替换为 0[0-9]

我想知道是否有办法在每个 1 位数字前面添加 0 使用regex.

输入字符串是由“-”分隔的 1-3 个数字的列表(即28, 12-56, 67-6, 45-65-46)。

我遇到的两个问题是:

  1. 匹配所有可能的 1 位数字,而不对以下各项进行单独检查:^[0-9]-, -[0-9]-, ^[0-9]&,-[0-9]&
  2. 添加 0 而不删除任何其他内容。所以把:Regex.Replace(input, "^[0-9]-","0")变成这样的东西:Regex.Replace(input, "^[0-9]-","^0[0-9]-")

.net c# regex

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

属性注入值在构造函数中为null

我正在使用OWIN中间件(使用startup.cs而不是global.asax)在我的ASP.NET MVC 5 Web应用程序中连接Autofac依赖注入,并尝试使用属性注入在Controller中设置公共变量.

我正在玩属性注入,让Autofac自动在LoginController中设置Test属性.

public interface ITest
{
    string TestMethod();
}

public class Test : ITest
{
    public string TestMethod()
    {
        return "Hello world!";
    }
}

public class LoginController : Controller
{
    public ITest Test { get; set; }

    public LoginController()
    {
        var aaa = Test.TestMethod();

        // Do other stuff...
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的startup.cs的样子.我一直在玩,所以可能不需要这些代码(或导致我的问题?).

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var builder = new ContainerBuilder();
        builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
        builder.RegisterType<Test>().As<ITest>().SingleInstance();
        builder.Register(c => new Test()).As<ITest>().InstancePerDependency();

        builder.RegisterType<ITest>().PropertiesAutowired();
        builder.RegisterType<LoginController>().PropertiesAutowired();

        builder.RegisterModelBinderProvider();
        builder.RegisterFilterProvider();

        var container …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection autofac property-injection

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

在 MVC 视图中渲染富文本?

我正在创建一个 asp.net MVC 应用程序,并且使用富文本在数据库中存储富文本。

从数据库中获取富文本并将其显示在“详细信息”页面上时,我不再看到格式化的数据。相反,我看到的是纯 html (例如<p><b><strong>富文本示例</strong></b></p>)
如何使用 Html.TextArea 等 Html 文本帮助程序按格式显示富文本而不是纯 html?

[AllowHtml]
public string Description { get; set; }
Run Code Online (Sandbox Code Playgroud)

我尝试将我的描述视图设置为这样而不是DisplayFor,但它仍然不起作用:

<dd>
    @Model.Description
    @*@Html.DisplayFor(model => model.Description)*@
</dd>
Run Code Online (Sandbox Code Playgroud)

html asp.net-mvc

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

如何从列表中获取随机项目

美好的一天,我有这个数组和列表,我想从列表中获取一个随机值

random Ram = new Random();
String[] Test= {"C2", "C3", "C4"};

List<String> LTest = new List<String>(Test);

String var = Ram.Next(LTest);
Run Code Online (Sandbox Code Playgroud)

错误 - 无法从 system.collection.generic.list 转换为“Int”

我还想继续从列表中删除该对象并将其添加到新对象中

Test.remove(Var);

newlist.add(Var);
Run Code Online (Sandbox Code Playgroud)

谢谢。

c# list

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

让我的手风琴动态响应?

我创建了一个手风琴组件,用于填充父组件动态提供的值。我无法实现的是每个手风琴都应该响应各自的点击。目前,无论我单击哪个手风琴,它都会折叠并展开第一个。这是我的代码:

数组parent.component.ts

import { Component, AfterViewInit, OnInit } from '@angular/core';

@Component({
    selector: 'my-array-parent',
    templateUrl: './array-parent.component.html',
})
export class ArrayParentComponent implements OnInit {
    private content: Test[];

    ngOnInit(): void {
        this.content = [{
            heading: 'header1',
            testData: [{
                title: 'title1',
                content: 'content1'
            }, {
                title: 'title2',
                content: 'content2'
            }]
        }, {
            heading: 'header2',
            testData: [{
                title: 'title1',
                content: 'content1'
            }, {
                title: 'title2',
                content: 'content2'
            }]
        }]
    }
}

export class Test {
    heading: string;
    testData: TestItem[];
}

export class TestItem {
    title: …
Run Code Online (Sandbox Code Playgroud)

accordion twitter-bootstrap typescript angular

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

隐藏导航栏,直到鼠标悬停

我试图隐藏导航栏(在一个名为nav-container的div中),直到用户将鼠标悬停在它上面,在这种情况下,它会滑出来呈现自己.我在下面写的JQuery代码似乎没有正常工作.任何帮助深表感谢!

HTML Navbar代码:

<div class="nav-container">
    <nav id = 'navbar'>

        <div class="link-container ">
            <a href='#' class="nav-link">Home</a>
        </div>

        <div class="link-container">
            <a href='#' class="nav-link">FAQ</a>
        </div>
        <div class="link-container">
            <a href='#' class="nav-link">List a Coin</a>
        </div>

        <div class="link-container">
            <a href='#' class="nav-link">Contact Us</a>
        </div>
    </nav>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS Navbar代码:

.nav-container{
    width: 110px;
    height: 230px;
    background-color: rgb(48, 162, 255);
    border: solid 2px none;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
}

#navbar{
    position: relative;
    margin: auto;
 }

.link-container {
    margin: 10px;
    font-size: 18px;
    width: 100%;
    color: white;
}

.nav-link{
    display:inline-block; …
Run Code Online (Sandbox Code Playgroud)

html css jquery navbar

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

没有路线与提供的值匹配

这个特殊案例不应该与任何其他线程重复 - 我相信我已经检查了所有这些并且我不相信任何具体提及这个案例。

我有这个控制器:

 namespace Cantrel.Application.CantrelSearchApi.Controllers
    {
        [Route("api/[controller]")]
        [Authorize]
        public class MonitorsController : Controller
        {
            private readonly IMonitoringApiService monitoringService;
            private readonly IClientsApiService clientsService;
            private readonly ILogger<MonitorsController> logger;

            public MonitorsController(IMonitoringApiService monitoringService,
                IClientsApiService clientsService,
                ILogger<MonitorsController> logger)
            {
                this.monitoringService = monitoringService;
                this.clientsService = clientsService;
                this.logger = logger;
            }


  [HttpGet("{id}")]
        public async Task<IActionResult> Get(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return BadRequest("No id was provided. Please provide a valid monitor id or subject id.");
            }

            try
            {
                MonitorDto monitor;

                if (Guid.TryParse(id, out Guid monitorId))
                { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-web-api

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

递归:显示从a到b的数字,并显示它们的总和

我想知道,总和来自哪里?我知道递归是什么,但我无法弄清楚如何int i获得总和.我已经读过关于堆栈......但我仍然不明白.请帮忙:)这里是代码:

static void Main(string[] args)
{
    int i = RecursiveMethod(1,3);
    //Console.ReadLine();
}

static int RecursiveMethod(int a, int b)
{
    Console.WriteLine(a);
    if (a == b)
    {
        return a;
    }
    else 
    {
        return a + RecursiveMethod(a + 1, b);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# recursion

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

如何重命名进入 Typescript 函数的变量?

尝试将此变量重命名assetPayoutType为 just payType,但是因为我在使用 TypeScript,所以出现了问题。TypeScript 认为有一种类型叫做payType.

const { title, assetPayoutType } = this.props;

mapDailyAssets(assetPayoutType: string)
Run Code Online (Sandbox Code Playgroud)

IE:这行不通:

mapDailyAssets(assetPayoutType: payType: string)
Run Code Online (Sandbox Code Playgroud)

我在 StackOverflow 上搜索,找到了两个没有回答这个问题的答案。

答案描述了非打字稿/常规 Javascript 简单重命名:

在 TypeScript 中解构对象时重命名剩余属性变量

这个答案是关于 VSCode 重构的:

TypeScript 重命名变量

javascript variables renaming typescript

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

对象的@property,tslint 给出错误 - no-redundant-jsdoc

我正在将 tslint 用于我的打字稿代码。我想记录接口的属性。tsLint 给出错误JSDoc tag '@property' is redundant in TypeScript code. (no-redundant-jsdoc)tslint(1)

以下是我的评论

/**
 * @property value - number with a unit as string
 */
Run Code Online (Sandbox Code Playgroud)

禁用下一行的 tslint 也不起作用。

jsDoc @property 和 tslint 禁用不起作用

javascript jsdoc typescript tslint angular

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