尽管我用谷歌搜索了一段时间,但我找不到服务器端Blazor的任何Model-View-XYZ框架实现,即Razor组件(XYZ代表以下任何一种:Controller,Presenter,ViewModel)。
如果有人知道这样的实现,无论它处于开发的哪个阶段,请告诉我。非常感谢。
编辑:问题是,是否有人遇到或参与了这种框架的开发。
这个问题非常简单 -有人在Internet上遇到过一些有关针对Razor组件(又称为服务器端Blazor)的框架的信息,因为到目前为止我还没有。
Since Wasm is written in non-human-readable form, does this make it nigh-on impossible for a hacker to look at the Wasm files of a site and figure out what's what?
I know it's never considered best practice to keep sensitive data on the client-side, but Wasm seems to be a bit of a game-changer when it comes to code obscurity (unless I've missed something somewhere).
Everything looks like this:
I don't see how any information can be gleaned from that. …
我在blazor中有简单的形式,如下所示。
<EditForm Model="@createInvoice" OnValidSubmit="@CreateInvoice" >
<DataAnnotationsValidator></DataAnnotationsValidator>
<p>
<label for="ddlService">Service</label>
<InputSelect id="ddlService" @bind-Value="@createInvoice.SelectedService">
<option value="0">Select Service</option>
@foreach (var item in Services)
{
<option value="@item.ServiceId">@item.Name</option>
}
</InputSelect>
<ValidationMessage For="@(()=> createInvoice.SelectedService)"></ValidationMessage>
</p>
</EditForm>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用数据注释属性来验证表单。使用editform的OnSubmit提交表单,但在提交之前未触发验证。如果我使用OnValidSubmit,它将触发验证。
有人可以解释OnSumbit,OnValidSubmit和OnInvalidSubmit如何工作。
我有一个名为BusinessUnit的对象,该对象包含子业务单位的列表,并且我需要一个函数来为其父项下的每个子项提供<li>元素。我到目前为止的代码如下:
<ul id="Level0">
@foreach (var bizUnit in businessUnitViewModel.BusinessUnitInfos)
{
<li>
<span>@bizUnit.BusinessUnitName</span>
<ul class="nested">
@foreach (var childOfbizUnit in bizUnit.Children)
{
<li>@childOfbizUnit.BusinessUnitName</li>
}
</ul>
</li>
}
</ul>
Run Code Online (Sandbox Code Playgroud)
嵌套的foreach与第一个嵌套的foreach基本相同,但是对其进行硬编码会限制我可以拥有的层次结构级别。我需要这样的功能:
public void HasKids(BusinessUnitInfo bizUnit)
{
foreach (var bizUnitChild in bizUnit.Children)
{
//Render an <li> tag element with bizUnitChild's
name<li>bizUnitChild.Name</li>
HasKids(bizUnitChild);
}
}
Run Code Online (Sandbox Code Playgroud)
是否有人知道我可以在最后一个代码块中为注释做些什么?如何使用C#代码动态呈现列表标记?坦:)
我想在每次单击按钮时通过动态添加其他 blazor 组件来更新视图。我怎样才能做到这一点。
例如:每次单击组件 1 上的按钮时,应立即将组件 2 添加到组件 1 中。
当输入(HTML)的值改变时,有没有办法调用方法?但不是当输入的焦点丢失时而是当我在 HTML 输入中输入字符时。
我使用@bind 将字段绑定到输入。
然后我尝试使用 @onkeydown 和 @onkeyup 来调用该方法。但是最后插入的字符还没有添加到有界字段中。
我也尝试使用@onchange,但随后我会收到错误消息“该元素的属性 onchange 被使用了两次或更多次。 - 我认为该债券也订阅了此事件。
我的最后一个想法是为债券使用(完整)属性而不是字段。在属性的 setter 中,我调用了该函数。但问题是,当 HTML 输入失去焦点时调用 setter。
<table class="table table-condensed table-hover" data-click-to-select="true">
<thead class="custom-headline">
<tr>
<th class="align-text-top">
@indexText.index_table_title<br />
<input type="text" @onkeydown="Test" @bind="titleSearch" />
</th>
...
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?
先谢谢了!
最好的问候马蒂亚斯
在下面的代码示例中,我在增量计数器演示中添加了逻辑以显示列表的内容,然后在点击事件中将“新项目”添加到列表中。但是,尽我所能尝试添加不添加...这两个 Console.WriteLine 尽职尽责地显示了添加前后三个成员的列表,但没有报告错误,列表也没有任何变化。
示例代码:
@page "/ListIncrement"
<div>
<p>Current count: @currentCount</p>
<ul>
@foreach (var ListItem in TestList)
{
<li>@ListItem</li>
}
</ul>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
</div>
@code {
private int currentCount = 0;
public List<string> TestList => new List<string>{
"one", "Two", "Three" };
private void IncrementCount()
{
currentCount++;
Console.WriteLine("Count= {0}", TestList.Count);
TestList.Add("New Item");
Console.WriteLine("Count= {0}", TestList.Count);
}
}
Run Code Online (Sandbox Code Playgroud) 我是 blazor 的新手,并尝试使用 .NET Core /EF Core 3 和 Visual Studio 2019 创建应用程序。我已经设置了一个数据库模型和一个 API,用于获取所有地址 (/api/Address) 并在浏览器中浏览到此返回数据库中的所有记录。但是我在 Razor 文件中的 My GetAsync 方法返回 401,最终返回 null。
这是我的剃刀代码:
@functions
{
Address[] addresses;
protected override async Task OnInitializedAsync()
{
addresses = await Http.GetJsonAsync<Address[]>("api/Address");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 API
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]
public class AddressController : ControllerBase
{
private readonly MyDataContext _context;
// GET: api/Address
[HttpGet]
public async Task<ActionResult<IEnumerable<Address>>> GetAddresses()
{
return await _context.addressesDbSet.ToListAsync();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的所有错误说
HttpRequestException: Response status code does not indicate success: 401 (Unauthorized). …Run Code Online (Sandbox Code Playgroud) 我刚刚发现 Microsoft 引入了 Blazor,它允许在浏览器中运行 C# 代码。当我查看一些教程时,您似乎需要 asp.net 核心后端服务器才能使其工作。如果我能在浏览器中输入 C# 代码就好了,比如:
<script>
//C# code
string myName = "John";
alert(myName);
</script>
Run Code Online (Sandbox Code Playgroud)
代替
<script>
//Javascript code
var myName = "John";
alert(myName);
</script>
Run Code Online (Sandbox Code Playgroud)
这能做到吗?
我想在剃刀组件中拆分代码。Html 标记和逻辑。我真的是新的 C#。当我像这样尝试时
TaskManagement.razor.cs:
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;
using MintWebApp.Services;
using MintDataService;
namespace WebApp.Pages
{
partial class TaskManagement
{
public TaskService _taskService;
public TaskManagement(TaskService taskService)
{
_taskService = taskService;
}
protected override async Task OnInitializedAsync()
{
MintTaskFromJson task = await _taskService.GetExampleTask();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
MissingMethodException: No parameterless constructor defined for type
'WebApp.Pages.TaskManagement'.
Run Code Online (Sandbox Code Playgroud)
哪个是将服务注入partinal类而不在razor文件中注入服务的最佳方式
blazor ×10
c# ×6
.net-core ×2
mvvm ×2
razor ×2
asp.net ×1
asp.net-core ×1
javascript ×1
mvp ×1
webassembly ×1