小编Kim*_*jan的帖子

ASP.NET MVC - 提取URL的参数

我正在尝试提取我的URL的参数,就像这样.

/行政/客户/编辑/ 1

提取物: 1

/管理/产品/编辑/ 18?允许=真

提取物: 18?allowed = true

/管理/产品/创建?允许=真

extract:?allowed = true

有人可以帮忙吗?谢谢!

c# asp.net-mvc asp.net-mvc-routing

55
推荐指数
2
解决办法
18万
查看次数

ASP.NET MVC中数据注释的默认资源

有一种方法可以将默认资源设置为数据注释验证吗?

我不想做这样的事情:

[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

18
推荐指数
2
解决办法
6844
查看次数

我该如何发送空值?

我想做这样的事情

$.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)

c# jquery json asp.net-mvc-2

5
推荐指数
1
解决办法
3931
查看次数

使用EF 4.3在LINQ内部规范

我偶然发现在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)

c# linq specification-pattern entity-framework-4

5
推荐指数
1
解决办法
2134
查看次数

如何将数据类型属性设置为smalldatetime

有办法吗?以下不起作用:

var customer = constructor.Entity<Customer>();
customer.Property(c => c.Date).DataType("smalldatetime");
Run Code Online (Sandbox Code Playgroud)

c# ado.net code-first entity-framework-4 c#-4.0

3
推荐指数
1
解决办法
2045
查看次数

T []和List <T>之间有什么区别?

实际上我总是使用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)

c# arrays generics c#-2.0

0
推荐指数
1
解决办法
196
查看次数