我正在测试一个null列表.每次我找到一个,我都将它保存在一个数组中,以在验证消息中实现它.
我想要的输出看起来像这样:
需要字段1
字段4是必需的
等等...
但我似乎无法开始一条新线.
现在,它看起来像这样:
需要字段1字段4是必需的
有谁知道如何实现这一目标?
编辑:
控制器:
IDictionary<int, String> emptyFields = new Dictionary<int, String>();
foreach (Something thing in AnotherThing.Collection)
{
if (thing.Property == null)
emptyFields.add(thing.Index, thing.Name);
}
if (emptyFields.Any())
throw new CustomException() { EmptyFields = emptyFields };
Run Code Online (Sandbox Code Playgroud)
此处处理此异常:
catch (CustomException ex)
{
ModelState.AddModelError("file", ex.GetExceptionString());
return View("theView");
}
Run Code Online (Sandbox Code Playgroud)
CustomException:
public class CustomException: Exception
{
public IDictionary<int,String> EmptyFields { get; set; }
public override String Label { get { return "someLabel"; } }
public override String GetExceptionString()
{ …Run Code Online (Sandbox Code Playgroud) asp.net-mvc newline line-breaks asp.net-mvc-3 validationmessage
我知道有很多问题可以解决这个特殊的错误,但在尝试了这些解决方案的组合后,没有人倾向于帮助这个包.
ng2-mdf-validation-messages - https://www.npmjs.com/package/ng2-mdf-validation-messages
在GitHub上还有一个问题仍然存在 - https://github.com/d-kostov-dev/ng2-mdf-validation-messages/issues/12
针对不同软件包的各种解决方案提到了导出函数并将其包含在内,useFactory但我没有得到为这个特定软件包编写的内容.
例如:
import { Ng2MDFValidationMessagesModule } from 'ng2-mdf-validation-messages';
export function Ng2MDFValidationMessagesModuleFactory() {
return Ng2MDFValidationMessagesModule.globalConfig({
class: 'text-danger',
defaultErrorMessages: {
required: 'Default Custom Required Message'
}
});
}
@NgModule({
...
providers: [
{
provide: Ng2MDFValidationMessagesModule,
useFactory: Ng2MDFValidationMessagesModuleFactory
}
],
})
Run Code Online (Sandbox Code Playgroud)
如果尝试使用创建的全新应用程序,它仍会出现错误ng.
编辑任何文件并保存后解决错误,之后一切正常,但不是第一次.
使用Angular 4和此插件添加带有全新安装的示例代码.
可在以下网址获得 - https://github.com/kunaldethe/ng4-mdf-validation-messages-example
组态:
1. node -v (v6.11.0)
2. npm -v (5.4.2)
3. ng --version
@angular/cli: 1.4.9
node: 6.11.0
os: win32 x64
@angular/animations: 4.4.6
@angular/common: …Run Code Online (Sandbox Code Playgroud)