我想显示一个存储在数据库中的图像,我的 DAL 中有这个函数,我将它注入到名为 admin 的组件中:
public byte[] GetCategoryLabelImage(int categoryLabelID)
{
var categoryLabel = context.CategoryLabels.FirstOrDefault(cl => cl.Id == categoryLabelID);
byte[] image = categoryLabel?.Image?.Image;
return image;
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用这样的标签时:
<img src="@admin.GetCategoryLabelImage(label.Id)" />
Run Code Online (Sandbox Code Playgroud)
它什么也没显示,这是显示图像的正确方法吗?
我有一个带有控制器方法的 Blazor Webassembly 项目,如下所示:
[HttpGet]
public async Task<List<string>> GetStatesForProfile()
{
IConfigurationSection statesSection = configuration.GetSection("SiteSettings:States");
var sections = statesSection.GetChildren();
var states = statesSection.GetChildren().Select(s => s.Key).ToList<string>();
return states;
}
Run Code Online (Sandbox Code Playgroud)
剃刀页面调用这个方法:
private async Task<bool> GetStatesModel()
{
try
{
States = await http.GetJsonAsync<List<string>>("api/account/getstatesforprofile");
...
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex.Message}, Inner: {ex.InnerException.Message}");
}
Run Code Online (Sandbox Code Playgroud)
我得到这个异常:
例外:“<”是值的无效开头。
我从 appsettings.json 文件中读取了这些值,并且值中没有“<”。
{
"SiteSettings": {
"States": {
"New York": ["NYC"],
"California": ["Los Angeles", "San Francisco"]
}
}
Run Code Online (Sandbox Code Playgroud)
此外,我在控制器方法中放置了一个断点,但它没有命中。这是什么错误?是从解析json吗?以及如何解决这个问题?
我有这段代码,我希望能够工作,但是 MarkupString 关闭了不应该关闭的标签:
@((MarkupString)startMarkup)
int count = 0;
foreach (int metaID in MetaIDs)
{
if (count % 3 == 0 && count != 0)
{
@((MarkupString)endMarkup)
}
<div class="col-md-4">
@: A component here
</div>
count++;
}
Run Code Online (Sandbox Code Playgroud)
有两个变量会自动关闭它们:
string startMarkup = "<div class=\"row\">";
string endMarkup = "</div><div class=\"row\">";
Run Code Online (Sandbox Code Playgroud)
如何使这个由 3 行项目组成的网格页面正常工作?
我使用布尔属性在用户单击按钮后禁用该按钮,以便单击不会发生两次。
private bool DisablePlaceOrderButton { get; set; } = false;
private void PlaceOrder_Clicked()
{
DisablePlaceOrderButton = true;
StateHasChanged();
if (cart.Lines.Count() == 0)
{
DisablePlaceOrderButton = false;
return;
}
...
}
Run Code Online (Sandbox Code Playgroud)
按钮设计如下:
<button @onclick="@PlaceOrder_Clicked" disabled="@DisablePlaceOrderButton">Place Order</button>
Run Code Online (Sandbox Code Playgroud)
但这不起作用,只有在 PlaceOrder 方法完成执行后按钮才会被禁用。我对 ajax 指示器也有同样的问题,在方法执行后应该显示,完成后应该隐藏,使用 if 块。在这两种情况下,statehaschanged 都没有效果。我使用 Blazor 服务器端预览 9。如何使这些工作?
我收到 HTTP错误 404.11 - 未找到请求过滤模块配置为拒绝包含双转义序列的请求。 当我向 Blazor 中的 .razor 页面发送请求时出错,链接是动态构建的并发送到用户电子邮件:
string confirmationLink = $"{HttpContext.Request.Scheme}://{Request.Host}/account/confirmemail/{System.Web.HttpUtility.UrlEncode(user.Id)}/{System.Web.HttpUtility.UrlEncode(confirmationToken)}";
Run Code Online (Sandbox Code Playgroud)
我在五个地方修改了 IIS Express 配置文件:
在所有情况下,我都修改了
<requestFiltering allowDoubleEscaping="true">
Run Code Online (Sandbox Code Playgroud)
“web.server”“安全”部分中的标记。但我仍然收到错误。有什么解决办法吗?
模型:
public class FiltersModel
{
public CheckBoxListWithTitle Brand { get; set; }
}
public class CheckBoxListWithTitle
{
public List<FilterCheckBox> CheckBoxes { get; set; }
}
public class FilterCheckBox
{
public string Value { get; set; }
public bool Checked { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
剃刀:
@foreach (var item in Model.Brand.CheckBoxes)
{
<label>
@item.Value
<input type="checkbox" @onchange="@FilterChangedBrand" />
</label>
}
Run Code Online (Sandbox Code Playgroud)
@代码:
public FiltersModel Model { get; set; } // Initialized in OnParametersSet
private void FilterChangedBrand(UIChangeEventArgs e)
{
string newCheckedBrand = e.Value.ToString(); …Run Code Online (Sandbox Code Playgroud) 由于即使在 EF core 6 中也无法翻译组联接查询,因此我将该查询编写为相关子查询。但我收到错误:
"查询包含类型为 'IQueryable' 的投影 'c => DbSet() .Where(c2 => c2.Country == c.Country) .AsQueryable()'。最终投影中的集合必须是 'IEnumerable'类型,如“List”。考虑使用“ToList”或其他一些机制将“IQueryable”或“IOrderedEnumerable”转换为“IEnumerable”。,内部:
以下 Linq 给我带来了这个错误:
IQueryable<CoronaVirus> covids = context.CoronaViruses.AsQueryable();
IQueryable<CoronaVirusDTO> covids2 = (from c in covids
let rt = context.CoronaViruses.Where(c2 => c2.Country == c.Country).AsQueryable()
select new CoronaVirusDTO()
{
Id = c.Id,
Country = c.Country,
Date = c.Date,
TodayCases = c.TodayCases,
TodayDeaths = c.TodayDeaths,
TotalCases = rt.Sum(it => it.TodayCases),
TotalDeaths = rt.Sum(it => it.TodayDeaths)
}).AsQueryable();
Run Code Online (Sandbox Code Playgroud)
如何更正此查询?
我使用这个项目并创建了一个完全一样的项目,但是收到
找不到路由值指定的回退端点:{ page: /_Host, area: }。
启动项目时出错,在启动配置方法中,我有:
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapDefaultControllerRoute();
endpoints.MapFallbackToPage("/_Host");
});
Run Code Online (Sandbox Code Playgroud)
如何解决此错误?
我在解决方案中有2个项目,一个是asp.net 5,另一个是包含EFModel的类库项目.我使用install-package安装:"EntityFramework":两个项目中的"6.1.3","EntityFramework.SqlServerCompact":"6.1.3",并在classlibrary\app.config和wwwroot\web.config中都有连接字符串我在互联网上搜索了一些说:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>?Run Code Online (Sandbox Code Playgroud)
在web.config中解决了这个问题,我在app.config中有这个部分,当我尝试将它放在web.config文件中时,我得到angularjs注入错误.我的实体框架代码给我错误:"指定的模式无效.错误:错误0152:找不到具有不变名称'System.Data.SqlClient'的ADO.NET提供程序的实体框架提供程序.确保...我我无法解决这个问题,请帮忙.
我想在 Blazor 服务器端应用程序中使用 TinyMCE,但它在页面加载时显示一秒钟然后消失。我归咎于它,StatehasChanged()因此我编写了一个重新初始化 TinyMCE 并OnAfterRender()在页面中调用的互操作函数。
这是 JS 互操作功能:
initTinyMce: function (tinyMceID) {
tinymce.init({
selector: 'textarea.tinyMce'
});
return "";
//var editor = tinyMCE.get(tinyMceID);
//if (editor && editor instanceof tinymce.Editor) {
// editor.init();
//}
}
Run Code Online (Sandbox Code Playgroud)
在OnAfterRender我这样称呼它:
protected override void OnAfterRender() {
base.OnAfterRender();
string a = jsInterop.InitTinyMce("myTinyMce").Result;
}
Run Code Online (Sandbox Code Playgroud)
但是它在出现后一秒钟就消失了。如何解决这个问题?
我想将数据从 Windows 窗体发送到 BlazorWebView 并接收从 Web 视图返回到窗体的通知。这个怎么做?在.Net6 Windows 窗体应用程序中。
BlazorWebView blazorApp = new BlazorWebView()
{
Dock = DockStyle.Fill,
HostPage = "wwwroot/index.html",
Services = serviceProvider
};
blazorApp.RootComponents.Add<App>("#app");
var form1 = new Form1();
form1.Controls.Add(blazorApp);
Application.Run(form1);
Run Code Online (Sandbox Code Playgroud) 我使用这段代码,但出现错误:
错误:System.ArgumentException:“...GreenPaperItem”类型的表达式不能用于方法“Boolean”的“System.Runtime.CompilerServices.Closure”类型的参数
public static Expression<Func<T, bool>> ToExpression<T>(Func<T, bool> p)
{
ParameterExpression p0 = Expression.Parameter(typeof(T));
ParameterExpression p1 = Expression.Parameter(typeof(bool));
return Expression.Lambda<Func<T, bool>>(Expression.Call(p.Method, p0, p1),
new ParameterExpression[] { p0, p1 });
}
Run Code Online (Sandbox Code Playgroud)
该表达式旨在用于 linq toEntity IQueriyable 查询:
query = query.Where(ToExpression<GreenPaperItem>(filter.GenerateFilterFunction()));
Run Code Online (Sandbox Code Playgroud) blazor ×8
c# ×3
.net ×1
angularjs ×1
asp.net ×1
expression ×1
iis-express ×1
javascript ×1
json ×1
lambda ×1
linq ×1
tinymce ×1
webview ×1