开发者

asp.net mvc default parameter attribute

开发者 https://www.devze.com 2023-03-05 03:42 出处:网络
Is there a way to set a default value on a parameter that was not passed, for eg: public ActionResult Index(int? page)

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

精彩评论

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