2017-05-05 63 views
0

我有我需要的可选参数的索引页必需的,所以我这样做:如何使/索引/没有在URL

[HttpGet] 
[Route("EventRegistration/Index/{status?}")] 
public ActionResult Index(string status) 
{ 
    .... 
} 

这个伟大的工程,只要是网址:

http://localhost:49698/EventRegistration/Index 

或者

http://localhost:49698/EventRegistration/Index/something 

但与此:

http://localhost:49698/EventRegistration 

它会抛出一个404.在添加可选参数之前,它没有`/ Index'就可以正常工作。我希望它继续这样做。

谢谢!

+1

应用两种路由属性? – CodeCaster

+0

不知道你可以做到这一点。第二个是什么样的? –

+2

'[Route(“EventRegistration”)]'我猜。 – CodeCaster

回答

1

这工作:

[HttpGet] 
[Route("EventRegistration/Index/{status?}")] 
[Route("EventRegistration")] 
public ActionResult Index(string status) 
{ 
    .... 
}