1

Do action methods require a view file (.cshtml)?

Do I have to create one for each method I create, or is it optional?

For example, if I do an HTTP post, and do a redirect to a different action method, a view file is not required, is this correct?

Rowan Freeman
  • 15,724
  • 11
  • 69
  • 100
user1929393
  • 4,089
  • 7
  • 30
  • 48
  • An ActionResult can return numerous types [refer this answer](http://stackoverflow.com/questions/1267043/all-inbuilt-actionresults-in-asp-net-mvc). It depend what you want to do. Not sure what you mean by the last statement. If your doing a post, then it implies you have a view to post from, so the associated GET method would return a view. –  Feb 06 '15 at 02:09
  • Sometimes I am posting a form from a partialview file, that is why I ask, that is nested within another view. – user1929393 Feb 06 '15 at 02:15
  • 1
    You only need a view if your method needs to return a view (i.e. you use `return View();` –  Feb 06 '15 at 02:21

1 Answers1

1

Correct. You don't need a view for an action.

In MVC, an action is whatever you make of it; it's taking a request, performing an action and returning a response.

What you do in the action is up to you, and there is no requirement for a view to exist or for you to return one.

Rowan Freeman
  • 15,724
  • 11
  • 69
  • 100