Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Unassigned: In MVC attribute routing, ignoring route prefix fails when '~/' template is used [1160]

$
0
0
__Scenario__:
User likes to make the HomeController's Index as the default view when anyone visits like "http://mysite.com"

__Issue__:
I am receiving the following validation error for the following controller:

__The route template '~/' on the action named 'Index' on the controller named 'Home' cannot begin or end with a forward slash.__

```
[RoutePrefix("Home")]
public class HomeController : Controller
{
//[HttpGet("~/")] //NOTE: Does not work
HttpGet("")]
[HttpGet("Index")]
public ActionResult Index()
{
return View();
}

[HttpGet("About")]
public ActionResult About()
{
ViewBag.Message = "About page";

return View();
}

[HttpGet("Contact")]
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";

return View();
}
}
```

__Workaround__:
User can remove the route prefix and instead do the following:
```
public class HomeController : Controller
{
[HttpGet("")]
[HttpGet("Home")]
[HttpGet("Home/Index")]
public ActionResult Index()
{
return View();
}

```

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>