开发者

asp.net mvc default parameter attribute

Is there a way to set a default value on a parameter that was not passed, for eg:

    public ActionResult Index(int? page)
    {}

I'd like to have page=0 if no page was passed, so I can remove the nullable symbol. I 开发者_如何学Pythondo not want to do this in routing, just on the action itself.


Have you tried:

public ActionResult Index(int page = 0)
{}


New in C# 2010 is the ability for optional parameters:

public ActionResult Index(int page = 0)     
{

} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜