我有一个只存在表单的页面,我希望将表单放在屏幕的中心.
<div class="container">
<div class="row justify-content-center align-items-center">
<form>
<div class="form-group">
<label for="formGroupExampleInput">Example label</label>
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Another label</label>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
</div>
</form>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
该justify-content-center对齐表格水平,但我无法弄清楚如何垂直对齐.我试过使用align-items-center和align-self-center,但它不起作用.
我错过了什么?
我有班级和财产.一些属性可以标记属性(它是我的LocalizedDisplayName继承DisplayNameAttribute).这是获取类的所有属性的方法:
private void FillAttribute()
{
Type type = typeof (NormDoc);
PropertyInfo[] propertyInfos = type.GetProperties();
foreach (var propertyInfo in propertyInfos)
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
我想在列表框中添加类的属性,在列表框中标记LocalizedDisplayName并显示属性的值.我怎样才能做到这一点?
编辑
这是LocalizedDisplayNameAttribute:
public class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
public LocalizedDisplayNameAttribute(string resourceId)
: base(GetMessageFromResource(resourceId))
{ }
private static string GetMessageFromResource(string resourceId)
{
var test =Thread.CurrentThread.CurrentCulture;
ResourceManager manager = new ResourceManager("EArchive.Data.Resources.DataResource", Assembly.GetExecutingAssembly());
return manager.GetString(resourceId);
}
}
Run Code Online (Sandbox Code Playgroud)
我想从资源文件中获取字符串.谢谢.
我今天更新了一个项目到ASP.NET Core 2,我收到以下错误:
不能从singleton IActiveUsersService使用作用域服务IMongoDbContext
我有以下注册:
services.AddSingleton<IActiveUsersService, ActiveUsersService>();
services.AddScoped<IMongoDbContext, MongoDbContext>();
services.AddSingleton(option =>
{
var client = new MongoClient(MongoConnectionString.Settings);
return client.GetDatabase(MongoConnectionString.Database);
})
public class MongoDbContext : IMongoDbContext
{
private readonly IMongoDatabase _database;
public MongoDbContext(IMongoDatabase database)
{
_database = database;
}
public IMongoCollection<T> GetCollection<T>() where T : Entity, new()
{
return _database.GetCollection<T>(new T().CollectionName);
}
}
public class IActiveUsersService: ActiveUsersService
{
public IActiveUsersService(IMongoDbContext mongoDbContext)
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
为什么DI无法使用该服务?一切都适用于ASP.NET Core 1.1.
我有td标签和几个div内部td:
<td>
<div class='test'></div>
<div class='test'></div>
</td>
<td>
<div class='test'></div>
</td>
Run Code Online (Sandbox Code Playgroud)
我想添加margin-bottom,div如果有多个td.我怎么能用css做到这一点?
我有一个类库项目(NotificationTemplate),它返回文件的内容:
public static class Template
{
public static string NotificatioEmail
{
get { return File.ReadAllText("Templates\\NotificatioEmail.cshtml"); }
}
}
Run Code Online (Sandbox Code Playgroud)
在这个项目中找到Templates带NotificatioEmail.cshtml文件的文件夹.
另外,我有两个应用程序:控制台应用程序和ASP.NET MVC应用程序.该文件在控制台应用程序中返回正常,但在MVC中我收到错误file not found.怎么写普遍?
我试过这个:
Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Templates",
"NotificatioEmail.cshtml")
Run Code Online (Sandbox Code Playgroud)
但BaseDirectory不包括bin文件夹.
我有一些对象:
var results= [
{
"_type": "MyType",
"_id": "57623535a44b8f1417740a13",
"_source": {
"info": {
"year": 2010,
"number": "string",
},
"type": "stolen",
"date": "2016-06-16T00:00:00",
"createdBy": "57469f3c71c8bf2479d225a6"
}
}
];
Run Code Online (Sandbox Code Playgroud)
我需要从数组中选择特定字段.结果,我想得到以下内容:
[
{
"_id": "57623535a44b8f1417740a13",
"info": {
"year": 2010,
"number": "string"
},
"type": "stolen",
"date": "2016-06-16T00:00:00",
"createdBy": "57469f3c71c8bf2479d225a6"
}
]
Run Code Online (Sandbox Code Playgroud)
如您所见,我想选择对象的_id字段和内容_source.我怎么能用lodash做到这一点?
我找到了.map函数,但它不需要一组键:
var res = _.map(results, "_source");
我需要动态创建textarea表单.我有以下模型:
this.fields = {
isRequired: true,
type: {
options: [
{
label: 'Option 1',
value: '1'
},
{
label: 'Option 2',
value: '2'
}
]
}
};
Run Code Online (Sandbox Code Playgroud)
形式:
this.userForm = this.fb.group({
isRequired: [this.fields.isRequired, Validators.required],
//... here a lot of other controls
type: this.fb.group({
options: this.fb.array(this.fields.type.options),
})
});
Run Code Online (Sandbox Code Playgroud)
模板的一部分:
<div formGroupName="type">
<div formArrayName="options">
<div *ngFor="let option of userForm.controls.type.controls.options.controls; let i=index">
<textarea [formControlName]="i"></textarea>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
所以,你可以看到我有一些对象,我想使用label属性来显示它textarea.现在我明白了[object Object].如果我options改为简单的字符串数组,如:['Option 1', 'Option 2'] …
我有几个项目,他们必须在单独的容器中运行,我有一些共享库也应该是buit.我发现了以下文章如何做到这一点.我将仅显示一个项目的docker文件,因为它们非常相似:
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS builder
WORKDIR /src
COPY *.sln ./
COPY Web/Web.csproj Web/
RUN dotnet restore
COPY . .
WORKDIR /src/Web
RUN dotnet build -c Debug -o /app
FROM builder AS publish
RUN dotnet publish -c Debug -o /app
FROM base AS production
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Web.dll"]
Run Code Online (Sandbox Code Playgroud)
因此,您可以看到使用多阶段建筑.如果我使用,docker-compose up那么一切正常.接下来,我试图通过Visual Studio运行它,我看到Output窗口中的所有步骤,但最后我收到以下错误:
目标进程退出但未引发CoreCLR启动事件.确保将目标进程配置为使用.NET Core.如果目标进程未在.NET Core上运行,则可能会出现这种情况.程序'[13] dotnet'退出代码145(0x91).程序''已退出代码145(0x91).
但是现在如何调试应用程序呢?这是github repo的链接.
PS.对于Tarun,VS生成的默认docker文件
FROM microsoft/aspnetcore:2.0
ARG …Run Code Online (Sandbox Code Playgroud) 我有一个全局ajaxComplete处理程序:
$('body').ajaxComplete(function (event, request, settings) {
if (request.getResponseHeader('REQUIRES_AUTH') === '1') {
alert("unauthorized");
};
});
Run Code Online (Sandbox Code Playgroud)
request总是在未定义中的问题仅被填充event.
你能解释一下为什么吗?
ajax请求的示例:
$.ajax({
cache: false,
data: "GET",
url: url,
success: function (content) {
$('#modal').html(content);
$('#modal').modal();
}
});
Run Code Online (Sandbox Code Playgroud)
更新:
来自API文档(感谢Austin Mullins):
但是,从jQuery 1.8开始,.ajaxComplete()方法只应附加到文档.
我已将代码更改为:
$(document).ajaxComplete(function (event, request, settings) {
if (request.getResponseHeader('REQUIRES_AUTH') === '1') {
alert("unauthorized");
};
});
Run Code Online (Sandbox Code Playgroud)
但现在我收到了错误:
TypeError: document.createDocumentFragment is not a function
safeFrag = document.createDocumentFragment(); (jquery-1.9.0.js (line 5800))
Run Code Online (Sandbox Code Playgroud)
浏览器是Firefox 19.0.2
解决方案: 问题出在Jquery 1.9.0版本中.我已更新到1.9.1,错误消失了.感谢波阿斯.
我有以下dto对象:
public class PriceDto
{
public string Ticker {get; set;}
public double Open {get; set;}
public double Close {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
源对象:
public class RemoteData
{
public Security Security { get; set; }
public IList<Prices> Prices{ get; set; }
}
public class Security
{
public string Ticker {get; set;}
}
public class Prices
{
public double Open {get; set;}
public double Close {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
结果,我想获得PriceDto对象的集合.我知道如何绘制Ticker属性.但是,我不知道如何Prices正确映射:
CreateMap<RemoteData, PriceDto>()
.ForMember(d => d.Ticker, opt => opt.MapFrom(s …Run Code Online (Sandbox Code Playgroud) c# ×5
asp.net-core ×2
css ×2
ajax ×1
angular ×1
asp.net-mvc ×1
automapper ×1
bootstrap-4 ×1
centering ×1
docker ×1
forms ×1
html ×1
javascript ×1
jquery ×1
jquery-1.9 ×1
lodash ×1
reflection ×1