Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If page = home display this div MVC

Im very new to MVC so I dont quite know how to go about displaying a div on the home page only. Basically it is a preloader that I dont want to display on any other page other than home.

I usually do this in .NET as follows:

      <%if(Request.Url.ToString().ToLower().Contains("default")) {%>
        <div id="PageLoader">
            <div class="PageLoaderInner">
                <div class="LoaderLogo"><img src="/Content/Images/Masterpage/Logo.png" width="127" height="125"/></div>
                <div class="LoaderIcon"><span class="spinner"></span><span></span></div>
            </div>
        </div>
      <%}%>

It is also a very basic website that I am making so I have removed the controller name out of the URL, in my case "Pages" so the URL displays /Contact instead of /Pages/Contact

Is there another way do display the div other than looking at the URL? It would be awesome if someone could show me how to do this in the Pages controller as well as "inline" in the HTML.

All the Pages controller displays at the moment is this:

namespace WebsiteName.Web.Controllers
{
    public class PagesController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

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

Thanks guys.

like image 624
dk_french032 Avatar asked Jun 03 '14 09:06

dk_french032


2 Answers

You can try this: Edit: without checking the URL

@{if(ViewBag.isHome)
   {
        <div id="PageLoader">
            <div class="PageLoaderInner">
                <div class="LoaderLogo"><img src="/Content/Images/Masterpage/Logo.png" width="127" height="125"/></div>
                <div class="LoaderIcon"><span class="spinner"></span><span></span></div>
            </div>
        </div>
      }
}

///Server

namespace WebsiteName.Web.Controllers
 {
    public class PagesController : Controller
    {
         public ActionResult Index()
         {
             ViewBag.isHome = true;
             return View();
         }

         public ActionResult Contact()
         {
             return View();
         }
    }
 }
like image 109
some_name Avatar answered Nov 10 '22 12:11

some_name


Just to explain a bit what Rosko said in the comment with a code

Layout Page

<div id="body">
        @RenderSection("SectionName", required: false)
        <section class="content-wrapper main-content clear-fix">
            @RenderBody()
        </section>
    </div>

Index Page

@section SectionName{
// your code
}

The Section SectionName will be rendered before the Index body and similarly you can redefine the place of the section as well.

like image 3
Arijit Mukherjee Avatar answered Nov 10 '22 13:11

Arijit Mukherjee