小编Pra*_*r J的帖子

如何使用 Blazor 使用 alert()、confirm() 和 prompt() 函数?

我正在学习 Blazor 技术。我在 VS 2019 中启动了一个默认的增量项目,并且我已经使用 confirm() 和 alert 修改了 Decrement 的代码,但它不起作用。

 @page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Increment</button>
<button class="btn btn-primary btn-danger" onclick="if (confirm('Are you sure to Decrement')) { @DecrementCount() }">Decrement</button>

@code {
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }

    private void DecrementCount()
    {
        currentCount--;
        // alert('Operation Successfully executed')
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的代码片段中,confirm() 函数运行良好,但我想调用 Decrement 函数不起作用构建失败。我想在我的函数中添加一条成功消息。请提供任何选项,而不是使用 confirm(),alert() 函数。

c# webassembly asp.net-core blazor asp.net-core-3.1

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

我应该在 C# 12 中为主构造函数参数创建私有属性吗?

我正在使用 C# 12。在 C# 12 中我可以使用主构造函数:

实施1:

public class Calculation(int a,int b)
{
  public int Addition() => a + b;
  public int Subtraction() => a - b;
}
Run Code Online (Sandbox Code Playgroud)

实施2:

public class Calculation(int a,int b)
{
 private int _a { get; init; } = a;
 private int _b { get; init; } = b;
 public int Addition() => _a + _b;
 public int Subtraction() => _a - _b;
}
Run Code Online (Sandbox Code Playgroud)

当我像这样调用这个方法时:

console.WriteLine(new Calculation(10,25).Addition());
Run Code Online (Sandbox Code Playgroud)

两种实现都工作正常,所以我想知道使用较长的实现 2 相对于较短的实现 1 是否有任何优势。

c# primary-constructor .net-8.0 c#-12.0

10
推荐指数
2
解决办法
1548
查看次数

如何使用 Asp.net 设置 .asmx webservice 启用跨源

我的网络服务代码是

 [WebMethod]
     public List<test> GetMachineData_List(string prefix, int person_id)
     {
         using (var db = new TestDB())
         {
             List<test> list = db.Fetch<test>("select id,name from machine_data_collection mc where mc.id=@0 and name like '%" + prefix + "%'", person_id);
             return list.ToList();
         }
     }
Run Code Online (Sandbox Code Playgroud)

我的 jquery Ajax 调用是

 $("#textbx").autocomplete(
            {
                source: function (request, response) {
                 $.ajax({
                        url: 'http://localhost:4787/ws/webservice.asmx/GetMachineData_List',
                        data: { prefix: request.term.toString() ,person_id:1},
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            var jsonArray;
                            try {
                                jsonArray = $.parseJSON(data.d); // using jQuery
                            } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net ajax jquery web-services

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

如何从特定的大约获得顶行.使用sql server 2008的百分比?

我需要约.每个日期30个百分点的数据.

id     name   datecol
-----------------------
1       A     2016-11-11
2       B     2016-11-11
3       C     2016-11-11
4       D     2016-11-11
5       E     2016-11-11
6       F     2016-11-11
7       G     2016-11-11
8       H     2016-11-11
9       I     2016-11-11
10      J     2016-11-11
11      A1    2016-11-12
12      B1    2016-11-12
13      C1    2016-11-12
14      D1    2016-11-13
15      E1    2016-11-13
16      F1    2016-11-14
17      G1    2016-11-14
18      H1    2016-11-14
19      I1    2016-11-14
20      J1    2016-11-14
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我有

2016-11-11 10行2016-11-12
2016-11-13
2行2016-11-14
5行

我需要这样的约.每个日期的顶行占30%,

id     name   datecol
-----------------------
1       A     2016-11-11
2 …
Run Code Online (Sandbox Code Playgroud)

sql sql-server sql-server-2008

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