walter_dl
walter_dl

Reputation: 309

¿Relation between Controller's Action Method and the Views?

I've a couple conceptual questions about the relationship between the Controller Action Method and the View:

Thanks to all

Upvotes: 0

Views: 247

Answers (1)

I would highly suggest running through a tutorial on MVC, such as this codeproject tutorial.

  • Naming convention are not set in stone, but in general allows for an understandable structure.
  • Yes, to navigate to a View you can specify the path. return View("~/this/is/your/path/ViewName.cshtml");
  • No. See above, you can return any view from any methods with the correct path, assuming the return type fits the return type of the method (Explained below).
  • View() is a C# "method" which tells the project to navigate to the View you specify, along with any parameters you pass. A more correct and in depth answer can be found by looking at the docs. The default return View() attemps to navigate to the return View("MethodName");
  • Action methods are methods with a return type of ActionResult. Redirect and View are examples of such. Think of them as similar to object return types, such as void or string, but instead ActionResult will tell your project to do something, such as redirect to another method or return a ViewResult via View().
  • No. Try it! It is however usually good practice, as it will easily separate your files by name, since you will likely have similar filenames n your project.

Upvotes: 1

Related Questions