2017-05-05 64 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) 
{ 
    .... 
}