为了显示集合中的项目,我会给asp-for标签标签助手的属性。下面的代码生成编译错误。
@foreach (var item in Model)
{
<label asp-for="item.BookingCode"></label>
}
答案 0 :(得分:22)
@foreach (var item in Model)
{
<label asp-for="@item.BookingCode"></label>
}
字符转义默认模型lambda代码。因此,您可以输入:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(managedObjectContextDidSave:) name:NSManagedObjectContextDidSaveNotification object:nil];
if (![[currentThread threadDictionary] objectForKey:@"managedObjectContext"]) {
NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] init];
// Configure Managed Object Context
[managedObjectContext setPersistentStoreCoordinator:_mOCMainSetting.persistentStoreCoordinator];
[[currentThread threadDictionary] setObject:managedObjectContext forKey:@"managedObjectContext"];
if (!_contextArray) {
_contextArray = [NSArray array];
}
NSMutableArray *mutableContextArray = [_contextArray mutableCopy];
[mutableContextArray addObject:managedObjectContext];
_contextArray = mutableContextArray;
}
NSManagedObjectContext *context = [[currentThread threadDictionary] objectForKey:@"managedObjectContext"];
options = (Options*)[context objectWithID:_optionsID];
return options;
}
- (void)managedObjectContextDidSave:(NSNotification *)notification {
// dispatch_async(dispatch_get_main_queue(), ^{
for (NSManagedObjectContext *context in _contextArray) {
[context mergeChangesFromContextDidSaveNotification:notification];
}
// });
}
答案 1 :(得分:-2)
我有一个简单的方法来做一个列表并显示它的属性。
List<string> razones = new List<string>();
foreach (var item in _context.Reason)
{
razones.Add (item.Description);
}
System.Diagnostics.Debug.WriteLine(razones.Count);