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.
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();
}
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With