Elaborate how view files are selected (#12806)

* Elaborate how view files are selected

When no name parameter is provided to a `View()` method, a view file with the same name of the caller action will be used, not an `Index.cshtml` view file by default.

* Update adding-view.md
pull/12912/head
Mojtaba Javan 2019-06-17 21:57:24 +04:30 committed by Rick Anderson
parent 034c5d7f8a
commit 19b31e3aa7
1 changed files with 1 additions and 1 deletions

View File

@ -67,7 +67,7 @@ Replace the contents of the *Views/HelloWorld/Index.cshtml* Razor view file with
[!code-HTML[](~/tutorials/first-mvc-app/start-mvc/sample/MvcMovie22/Views/HelloWorld/Index1.cshtml?highlight=7)]
Navigate to `https://localhost:xxxx/HelloWorld`. The `Index` method in the `HelloWorldController` didn't do much; it ran the statement `return View();`, which specified that the method should use a view template file to render a response to the browser. Because you didn't explicitly specify the name of the view template file, MVC defaulted to using the *Index.cshtml* view file in the */Views/HelloWorld* folder. The image below shows the string "Hello from our View Template!" hard-coded in the view.
Navigate to `https://localhost:xxxx/HelloWorld`. The `Index` method in the `HelloWorldController` didn't do much; it ran the statement `return View();`, which specified that the method should use a view template file to render a response to the browser. Because a view template file name wasn't specified, MVC defaulted to using the default view file. The default view file has the same name as the method (`Index`), so in the */Views/HelloWorld/Index.cshtml* is used. The image below shows the string "Hello from our View Template!" hard-coded in the view.
![Browser window](~/tutorials/first-mvc-app/adding-view/_static/hell_template.png)