Vasil Ivanishvili
Vasil Ivanishvili

Reputation: 47

Difference between passing and not passing a view name in the View() method when we return from an Actionresult

What is the difference between passing and not passing a view name to the View() method in an Action?

public ActionResult Index()
        {
            return View();
        }

VS

public ActionResult Index()
        {
            return View("Index");
        }

What does view() return in the case of receiving no argument?

Upvotes: 0

Views: 43

Answers (1)

Md Rahatur Rahman
Md Rahatur Rahman

Reputation: 3244

If you do not pass the name of the view it would pass the name of the action. In your case when you write return View(); it would be like writing return View("Index");

This is helpful in case your action name changes. Pass the view name only when you are using a shared view in multiple actions. For other cases leave it empty.

Upvotes: 1

Related Questions