Zerotoinfinity
Zerotoinfinity

Reputation: 6540

unable to set layout page for a view

I have created a helloWorldController, for which I have created a index method

enter image description here

Here is the view code which is generated for me

    @{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

and my _layout page is default ASP.NET MVC 4 layout. But still I am getting blank page with the string returned from the Index method.

How can I enable _Layout page for a view?

Upvotes: 0

Views: 156

Answers (1)

levelnis
levelnis

Reputation: 7705

If that screenshot is the actual code for your controller, you need to return ActionResult for each action method rather than string, e.g.

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

The View() return value will work provided that there is a view called Index.cshtml in either your Views\HelloWorld or Views\Shared folder. The convention is that you have a specific folder with the same name as your controller for all views specifically relating to that controller - in your case HelloWorld

Upvotes: 2

Related Questions