I have ASP.Net MVC 5 application with Layout.cshtml and I have included the HTML view page. But I want to keep the consistent look and feel across multiple views in my application. I know I can do this if I have a Razor view page:
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
If I'm also using the same above code on the HTML View page, it doesn't pick up the Layout as it does in Razor page.
In html page you can't call '_Layout.cshtml' file directly to use layout , you have to add style and html tags manually in new created html file which you have in '_Layout.cshtml'. There is an option to call '_Layout.cshtml' using iframe but it is useful only if you don't want to apply server side logic, which is of less possibility.
Related
I'm creating a new website and I will have different pages on it. However, instead of creating new HTML files for each page and an anchor for each, I want all my pages contained in one HTML file. Is it possible in any way?
You can try Vue js or React js or many js frameworks ... which contain components.
Using HTML
You can control HTML page section how tabs working in HTML, take a look in Bootstrap Tabs, or you can hide/show sections using CSS or using JS, you may store HTML for each page in array of js and load that HTML to Body based on URL you create
Using Server Side Language
Also if you need single page application with multiple pages you need a Server Side language, where Database contains your website configurations and you can load based on the URL each page's layout or text like heading forms etc...
I have pretty simple landing site (index, faq, about, contact) based on ASP.net MVC. Of course, I use Layout (with head and footer), every View contains just page content. The problem: some pages has unique footer or head.
For example:
Index page has carousel (only this page, other pages has no carousel).
In source HTML (that web-designer sent me) I see scripts links in the head and scripts block in the end. Yes, I know: I can use Razor tag "#section" and declare this non-standard head and footer inside my view.
But! It means my view (page content) includes razor syntax. This is not pure HTML. What if site admin will want to edit index page - he will see Razor tags, he can't use some html editor or online tool (TinyMCE) for edit. He must know Razor. He can't just insert pure html.
Maybe I shouldn't keep page contents in DB? (but this site must support multi-lang). What is the best approac in this case?
Thanks.
I have an html template, that describe the position of each control and templates are getting from database. I have added certain custom tags like [txt],[chk] into html template. I want to replace this tags with asp.net controls like textbox,checkbox etc... at the time of page rendering. so i can write c# code on these controls.I want to implement these things on code behind.
If you are using ASP.net web forms, simply copy your HTML template into an ASPX page and replace your placeholders with the relevant controls you want to use.
If you are using ASP.Net MVC, then you can use Razor to do this. http://weblogs.asp.net/scottgu/introducing-razor
I am using ui-router of angularjs in my SPA. When i add an style to my view pages, angularjs loads them when switching to than view. Thats actually pretty cool that it can be done in runtime.
The problem is i do not want it to do so. for example i want to use bootstrap css in my view. it is already inserted in the main page, so it is not needed to get loaded again form child view. but for my IDE to auto-complete class names, it is needed to be added to html page of subview.
Is there any way to ask Angularjs to ignore Head part and just load Body part of my html?
I created a mvc4 web app. with razor view engine. There are Layout page and content pages(Home, Contact, About, etc.) you know. But there is no reference to layout from content pages.
Should do not content pages include this:
Layout = "~/Views/Shared/_Layout.cshtml";
In content pages this code is missing.And they works.
How does it do this without layout reference?
It's because partial views are included into a 'non-partial' page, which does have a layout defined.. So they make use of that and just become a part of that page
EDIT
I'm sorry for the late reply, I just checked it out and it appears to be cause of the _ViewStart.cshtml page, this is a page that runs before any view is rendered, read more here:
weblogs.asp.net/gunnarpeipman/archive/2010/10/10/…
thats your masterpage if you want a partial view
#Html.Partial("partialviewname". "controller")
and the partial view doesnt use the masterpage since it is inserted to a place you desire