Set background image for Index view only in Home controller - asp.net-mvc

I am developing website for music school. I want to set a background image for sign in page only. How can I do that?
#Html.ActionLink("EntryMode","EntryMode","Home")
#Html.ActionLink("Students","Index","Students")
#using (Html.BeginForm(new { #class = "form login-form" }))
{ ....
//form code here
}

If you want to have a different background in a view, you have to make appropriate changes in the markup of that view, not in the _Layout.cshtml file. This can be made by simply wrapping the content of that page, for example, in a
<body style="background-image:url('background.png');">
</body>
tag, but it depends on the markup you already have.
Provide your code, it will help giving more certain answer.
UPD :
Add this to the view
<style>
body { background-image: url("background.jpg"); }
</style>

If you're using a layout page you could add the name of the controller as class on the body. That way you can do lots of controllerdriven layout manipulation. At least that's how i'd do it.
Something along the lines of this: (untested, edit at will)
<body class="controller-#ViewContext.Controller.GetType().Name">
<div id="yourheaderimage">
<img .../>
</div>
</body>
combined with css
#yourheaderimage {
display: none;
}
controller-HomeController #yourheaderimage {
display: block;
}

Related

Jquery Mobile: Embed external HTML file without iframe

How can I load a external html page in a div?
<div data-role="page" id="pageone">
<div data-role="panel" id="myPanel">
<!--Load nav.html here-->
</div>
...
I have tried with following code but it doesn't function.
$( "#myPanel" ).load( "nav.html" );
See: http://plnkr.co/edit/N6xTrvLHWdOMG9Lq?open=lib%2Findex.html
The panel is expecting some markup as content, not a whole HTML page.
This will load Your navigation listview inside the panel:
$(document).on('panelcreate', '#myPanel', function () {
$(this).children(".ui-panel-inner").load("nav.html ul", function() {
$(this).enhanceWithin().trigger("updatelayout");
});
});
The full-width listview is requiring some additional CSS:
/* The left reveal panel shadow is 5px inset and blurred by 5px */
.ui-panel-display-reveal.ui-panel-position-left .ui-listview {
margin-right: -10px;
}
EDIT:
To test Your navigation menu and see if it looks as intended, You may design it directly inside the panel. To allow the framework to create the panelInner, simply put somewhat inside the panel div, i.e. a placeholder div or, as said, even better the static version of Your navigation menu. Thus, it will be then correctly replaced by Your external version.
In one word, instead of <!--Load nav.html here--> write <div>...</div>.

Hide Render page in some views Razor

In my mvc app I a have made one footer and embedded it like this
<div class="off-canvas-wrap" data-offcanvas>
<div class="inner-wrap">
#Html.Action("Menu", "Site")
<aside class="main-section">
#RenderBody()
</aside>
#RenderPage("~/Views/Shared/DisplayTemplates/_footer.cshtml")
</div>
</div>
This code lies in my _layout.cshtml file, what I am trying to do here is to hide the footer on a certain page. Is it even possible to hide the footer on a particular page?
Looking forward for suggestions.
Add css to that page.cshtml that you want to hide the footer at.
footer {
visibility: collapse;
}
Yes, you can do that several ways, the first one using C# in Razor:
#if (myCondition)
{
#RenderPage(...);
}
or you can have JavaScript with jQuery do it:
<script>
$(function() {
if (myConditionInJavaScript) {
$("#myfooter").hide();
}
});
</script>
The JavaScript code above will be executed automatically once the entire page is loaded, thanks to the $(function() { ... }) jQuery functionality.
If you want to hide a footer for example from your layout, you can do like this:
In _layout:
#if (IsSectionDefined("hidefooter"))
{
#RenderSection("hidefooter", false)
}
else // Just regular footer from layout
{
<footer class="footer top30">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<p>Copyright © ABC</p>
</div>
</div>
</div>
</footer>
}
In chtml file:
#section hidefooter {}
You have multiple options
User jquery code to hide the footer div on that particular page.
use $('#footerId').hide(); on that particular page.
Use can set a viewbag on particular actionresult and check on the layout page that viewbag is set than hide otherwise keep as it is.
ex.
#if(Viewbag.ShowFooter!="False")
{
#RenderPage("~/Views/Shared/DisplayTemplates/_footer.cshtml")
}
Since your condition will be in the page being rendered and not the layout you will either have to keep some global function which can be called after the page is loaded.
Something like
window.myfunction =function() {
if (myConditionInJavaScript) {
$("#myfooter").hide();
}
}
and call this function in your child page. by window.myfunction();
Also you can use Viewbag but you need to set the value of the ViewBag in each view when it is being rendered or updated.
Most efficent way according to me would be maintaining two separate layouts if you have just one section that has to be hidden. Because whichever way you choose at every page load the condition will be fired which may result in a degraded performance.

How to make nested layouts with jquery-layout resizable?

I'm trying to create a 4-pane layout using the jQuery-Layout plugin.
Really basic stuff:
The layout (note that I use iframes):
<iframe class="ui-layout-center">Outer Center</iframe>
<iframe class="ui-layout-east">Outer East</iframe>
<div class="ui-layout-west ">
<iframe class="ui-layout-south">Middle South</iframe>
<div class="ui-layout-center ">
<iframe class="ui-layout-center">Inner Center</iframe>
</div>
</div>
The initialization:
$(document).ready(function () {
$('body').layout({
west__childOptions: {
center__childOptions: {
}
}
});
});
Here's a fiddle.
Updated, simpler fiddle.
All is well until I try to resize the panes. It kinda works, but is very rough. When dragging the pane resizer handles it looks like they lose contact with the mouse pointer and stop resizing.
If the panes are simple divs, everything works, but not if the panes are iframes (which is what I need).
Any idea on how I could debug this?
I have found the answer here
Basically, you need to mask each panel (and its parents, in case of nested panels) that contains an iframe.
Like this:
$('body').layout({
center__maskContents: true,
west__maskContents: true
});
Here's the working demo of the fiddle from the question: click

Jquery mobile loses custom style after button text changed

I have a simple (newbie here) task in jquery mobile. Change the text of a button which has a custom style applied. I can change the text without problem in the 'pageinit' event however I lose the custom style in the process. Have read lots of article in stackoverflow but still lack a working solution.
Excerpt of html page below loaded by ajax
CSS
#goal .ui-btn-inner {
text-align: center;
background: chartreuse;
ui-disabled: true;
}
Button to be styled
<div data-corners="false" data-role="controlgroup" >
<a href="#" data-role="button" id="goal" >
text to be changed
</a>
</div>
...
Here is the jquery mobile code that changes the button text.
$(document).delegate('#problem_screen', 'pageinit', function() {
$('#goal').on('click', function() {
console.log('goal clicked');
});
$('#goal .ui-btn-text').text('New button text');
});
Thanks
Finally got this to work. My first JQM mistake was to define custom styles on each page of the multiple page application. This is wrong -- you must define all your custom styles in one location, typically a style sheet file which is included by every page. Another mistake is to have same id value on different pages. Wrong -- id values must be unique throughout application.
The api that applies (in this case enhances a style) is .addClass("). In my case I defined a style as follows:
.goal-style {
text-align: center;
background: charteuse;
ui-disabled: true;
}
Now after I update the button's text I say:
$('#goal').addClass('goal-style'); // Note: do not use '.goal-style'

How to clear all anchor styling from #Html.ActionLink

In my MVC application, I have used #Html.ActionLink. I have set their styles to display them like a button, but the problem is that there are stome styles for a, a:link, etc (I mean, all anchor behaviors) in the CSS file, and that is why the links on #Html.ActionLink appears like links, and not plain text. Any idea to get rid of all anchor behavior for those particular #Html.Actionlink controls?
Is using jQuery an option? You could write a function to remove the css from each link on startup.
$(document).ready(function() {
// to clear css from a specific item
$("#your-link-id").removeClass();
// to clear css from a bunch of links
$("your-selector a").each(function() {
$(this).removeClass();
});
});
Or you could create additional css classes that override the styles on your a tags.
<style type="text/css">
.whatever { background-color:black !important; }
</style>
#Html.ActionLink("MyAction", "MyController", new { #class = "whatever" })

Resources