2

I am new to MVC3 and so far I think its awesome. Very different however.

In one directory there is hundreds of .cshtml names in a format of: 01-01-01.cshtml. I cant return this view from the controller because the format of the named .cshtml is not recognised.

This link: How to get current page URL in MVC 3

It has a similar problem but is not the same.

What would be the best, fastest way to handle this problem without renaming all my files? (I don't want to do this)

Community
  • 1
  • 1
Rusty Nail
  • 2,692
  • 3
  • 34
  • 55
  • 1
    http://stackoverflow.com/questions/2070890/asp-net-mvc-support-for-urls-with-hyphens – PSL May 17 '13 at 22:37
  • Thx PSL - I did a test and the problem is the numbers, not so much the hyphens. I created a test page with 1234.cshtml and have the same issue as I do with the pages 01-01-01.cshtml – Rusty Nail May 17 '13 at 22:46
  • Just did another test with U-01-01-01 and now the Hyphens are an issue so this may help me after all - Thanks. – Rusty Nail May 17 '13 at 22:54
  • http://stackoverflow.com/a/4969381/1183804 - This answer works if I use U-01-01-01.cshtml and call @Html.ActionLink("", "U-01-01-01", "") - [ActionName("U-01-01-01")] public ActionResult U010101() { return View(); } – Rusty Nail May 17 '13 at 23:24

1 Answers1

2

The credit here is PSL's I have used that information to solve this problem. Also Credit to: stackoverflow.com/a/4969381/1183804 for initially posting this answer.

My cshtml Name:

01-01-01.cshtml

In the Controller:

[ActionName("01-01-01")]
public ActionResult U010101()
{
    return View();
}

and to call this View:

@Html.ActionLink("<LinkName>", "01-01-01", "<ControllerName>") 

Again this credit needs to go to PSL from the comments above.

Hope this helps others.

Rusty Nail
  • 2,692
  • 3
  • 34
  • 55