我在"数据连接"(在"服务器资源管理器"视图中)连接到外部SQL服务器.我可以右键单击我的SQL源并单击"新建查询"以使用SQL语句快速查找数据.
我想改用LINQ,我认为"C#Interactive"窗口是一个很好的快速方法.我的问题是我不知道如何访问我的"开放"数据连接.无法识别数据库的名称.
我想翻译验证消息"字段日期必须是日期".
我已将以下键添加到Global.asax的Application_Start()中
ClientDataTypeModelValidatorProvider.ResourceClassKey = "ModelBinders";
DefaultModelBinder.ResourceClassKey = "ModelBinders";
Run Code Online (Sandbox Code Playgroud)
我在App_GlobalResources中创建了ModelBinders.resx,ModelBinders.nl.resx,ModelBinders.fr.resx.
我在.resx文件中添加了以下字符串资源(或翻译):
Run Code Online (Sandbox Code Playgroud)Name Value ==== ===== FieldMustBeDate The field {0} must be a date. FieldMustBeNumeric The field {0} must be a number. PropertyValueInvalid The value '{0}' is not valid for {1}. PropertyValueRequired A value is required.
当我提交日期字符串时,我将收到"FieldMustBeDate"的翻译.当我提交无效日期(例如"01/01/201a")时,我收到默认ModelBinders.resx中定义的"PropertyValueInvalid"的未翻译消息,而不是翻译...如何显示正确的翻译for PropertyValueInvalid?
我有一个这样的模型:
[IsValidInput]
public class Input
{
//different properties
}
Run Code Online (Sandbox Code Playgroud)
使用这样的自定义验证属性:
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class IsValidInput : ValidationAttribute
{
public override bool IsValid(object value)
{
try
{
ExternalValidator.Validate(value);
}
catch (CustomException ex)
{
foreach(var errorText in ex.GetDescriptions())
{
this.ErrorMessage = this.ErrorMessage + errorText;
}
return false;
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个包含多个错误的 ErrorMessage 对象。我想以某种方式返回多个 ErrorMessage 对象,这样在我看来,我将拥有一个包含多个列表项的列表,如下所示:
如何返回 ErrorMessages 列表来解决这个问题?
c# ×3
asp.net-mvc ×2
asp.net ×1
global-asax ×1
interactive ×1
localization ×1
sql-server ×1
validation ×1