我正在尝试提取我的URL的参数,就像这样.
/行政/客户/编辑/ 1
/管理/产品/编辑/ 18?允许=真
/管理/产品/创建?允许=真
有人可以帮忙吗?谢谢!
有一种方法可以将默认资源设置为数据注释验证吗?
我不想做这样的事情:
[Required(ErrorMessage="Name required.", ErrorMessageResourceType=typeof(CustomDataAnnotationsResources)]
public string Name { get; set; }
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
Global.asax中
DataAnnotations.DefaultResources = typeof(CustomDataAnnotationsResources);
Run Code Online (Sandbox Code Playgroud)
然后
[Required]
public string Name { get; set; }
Run Code Online (Sandbox Code Playgroud)
有人给我一个光!
提前致谢
编辑
我真正的问题是使用EF Code First CTP4.CTP5修复它.谢谢大家.
.net asp.net-mvc-2-validation data-annotations asp.net-mvc-2
我想做这样的事情
$.get('/Controller/Action/', { model : null }, function(data) {});
Run Code Online (Sandbox Code Playgroud)
不幸的是,它不起作用.在服务器端,模型的值是{object}
.
我怎么得到null
?
编辑
--- Javascript ---
var json = JSON.stringify({ model: null });
$.get('/Controller/Action/', json, function (data) { });
Run Code Online (Sandbox Code Playgroud)
---控制器---
[HttpGet]
public ActionResult Test(object model)
{
// here i need model = null but keep returning {object}
return PartialView("TestPartial");
}
Run Code Online (Sandbox Code Playgroud) 我偶然发现在LINQ查询中使用我的规范.麻烦在于我的规范与params.
让我们假设一个简单的场景:
public class Car {
public Guid Id { get; set; }
public string Color { get; set; }
public int UsedPieces { get; set; }
// whatever properties
}
public class Piece {
public Guid Id { get; set; }
public string Color { get; set; }
// whatever properties
}
public static class PieceSpecifications : ISpecification<Piece> {
public static ISpecification<Piece> WithColor(string color) {
return new Specification<Piece>(p => p.Color == color);
}
}
Run Code Online (Sandbox Code Playgroud)
我真正想做的事情
// Get accepts ISpecification …
Run Code Online (Sandbox Code Playgroud) 有办法吗?以下不起作用:
var customer = constructor.Entity<Customer>();
customer.Property(c => c.Date).DataType("smalldatetime");
Run Code Online (Sandbox Code Playgroud) 实际上我总是使用Generic Collections而且我经常使用List <>.我觉得有些场景new List<string>()
非常难看,我更喜欢使用string[]
,但是我不使用它,因为据我所知,泛型有更好的性能,因此我使用它们.
string [],int []或任何非泛型数组对应用程序有害吗?
我只是想知道阵列和通用集合之间的区别是什么.
编辑:
让我们假装一个场景
我必须使用这种方法,我应该使用string[]
或List<string>
?什么更好?
static void PrintValues(IEnumerable<string> values) {
foreach(var value in values) {
Console.WriteLine(value);
}
}
Run Code Online (Sandbox Code Playgroud)