Layout page's code not being sent to content pages - razor

I have a _SiteLayout.cshtml file which structures the site and has some C# code on it. How do I send the _SiteLayout's C# code to all of its subpages? I am using WebPages Razor 2.
Thank you in advance.

There are two methods for implementing a layout page:
use the Layout command in the code section of every page, as outlined in Creating a Consistent Layout in ASP.NET Web Pages (Razor) Sites
or initialize the same layout page for all files in a single folder using the _PageStart.cshtml file(Customizing Site-Wide Behavior for ASP.NET Web Pages (Razor) Sites).
In the latter case you could disable the layout page for a single page using Layout = null in the code section.
Edit
If you want to pass data from a master page to a partial page, you must use the RenderPage() method instead of the RenderBody() method, but the structure of your site fully changes.
If, by example, you want to create a master page that extracts data from a table and passes them to a partial page that can change, your master page could be something like:
#{
var db = Database.Open("Northwind");
var data = db.Query(#"SELECT [Product Id], [Product Name],
[English Name] FROM Products ");
var page = "Partial.cshtml";
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
#RenderPage(page, new {gridData = data})
</body>
</html>
The code in Partial.cshtml takes data from the Page.gridData variable and displays them in a WebGrid:
#{
var grid = new WebGrid(Page.gridData);
}
<div>#grid.GetHtml()</div>

Related

i want to display data as json in html

i'm using this 1 as api for my flutter app ( get data for FutureBuilder 2)
i want to make page like it to could put my data in it ,I tired to put my data in html file and upload to
3,it seems like it 4
<body>
<div>{"page":1,"per_page":6,"total":12,"total_pages":2,"data":[{"id":1,"email":"george.bluth#reqres.in","first_name":"George","last_name":"Bluth","avatar":"https://reqres.in/img/faces/1-image.jpg"},{"id":2,"email":"janet.weaver#reqres.in","first_name":"Janet","last_name":"Weaver","avatar":"https://reqres.in/img/faces/2-image.jpg"},{"id":3,"email":"emma.wong#reqres.in","first_name":"Emma","last_name":"Wong","avatar":"https://reqres.in/img/faces/3-image.jpg"},{"id":4,"email":"eve.holt#reqres.in","first_name":"Eve","last_name":"Holt","avatar":"https://reqres.in/img/faces/4-image.jpg"},{"id":5,"email":"charles.morris#reqres.in","first_name":"Charles","last_name":"Morris","avatar":"https://reqres.in/img/faces/5-image.jpg"},{"id":6,"email":"tracey.ramos#reqres.in","first_name":"Tracey","last_name":"Ramos","avatar":"https://reqres.in/img/faces/6-image.jpg"}],"support":{"url":"https://reqres.in/#support-heading","text":"To keep ReqRes free, contributions towards server costs are appreciated!"}}</div>
</body>
put when I use postman 5 it read link as HTML ,I want postman read it like json
to could use it in flutter
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
let data = {"page":1,"per_page":6,"total":12,"total_pages":2,"data":[{"id":1,"email":"george.bluth#reqres.in","first_name":"George","last_name":"Bluth","avatar":"https://reqres.in/img/faces/1-image.jpg"},{"id":2,"email":"janet.weaver#reqres.in","first_name":"Janet","last_name":"Weaver","avatar":"https://reqres.in/img/faces/2-image.jpg"},{"id":3,"email":"emma.wong#reqres.in","first_name":"Emma","last_name":"Wong","avatar":"https://reqres.in/img/faces/3-image.jpg"},{"id":4,"email":"eve.holt#reqres.in","first_name":"Eve","last_name":"Holt","avatar":"https://reqres.in/img/faces/4-image.jpg"},{"id":5,"email":"charles.morris#reqres.in","first_name":"Charles","last_name":"Morris","avatar":"https://reqres.in/img/faces/5-image.jpg"},{"id":6,"email":"tracey.ramos#reqres.in","first_name":"Tracey","last_name":"Ramos","avatar":"https://reqres.in/img/faces/6-image.jpg"}],"support":{"url":"https://reqres.in/#support-heading","text":"To keep ReqRes free, contributions towards server costs are appreciated!"}}
data = JSON.stringify(data,null,4)
$('pre').text(data)})
</script>
</head>
<body>
<pre>Toggle between slide up and slide down for a p element</pre>
</body>
</html>
use pre tag to display as it will show the text in formatted structure, use script section to format the test. use JSON.stringify(data,null,intent) to format the data

Other pages do not see the layout page

I am working .netcore project.Admin Areas other pages do not see the layout page.I know how it works. I have also done what happened on many sites but it has not been resolved.viewstart's page code:
#{
Layout = "_Layout";
}
Dosya düzeninin fotoğrafı:
Just change Layout to the following url which is the layout.cshtml in Admin area:
#{
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}

Get a copy of Body to make a "preview" window

I'm basically doing a mail-merge (replacing Total: $ {total_amount} for Total: $ 20.00) in a Google Docs document with Google App Script.
However, I want a preview option, where I show a modal dialog or something, and then I append to it a copy of the Body of the actual document. That way I can replace all the variables and keeping the original format (bold, italics, etc).
I already have an implementation that loads the current document as HTML exported and appends it to the dialog.
html = getGoogleDocumentAsHTML();
replaced = replace(html);
output = HtmlService.createHtmlOutput(replaced)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(700)
.setHeight(500);
DocumentApp.getUi().showModalDialog(output, 'Preview');
/*
* #see http://stackoverflow.com/questions/14663852/get-google-document-as-html#answer-28503601
*/
function getGoogleDocumentAsHTML(){ ...
But with this approach I am unable to show the pages, so that the user knows the paragraphs that fits on each page, layout, etc.
Is there any way to get a copy of the Document's Body to do this, or a similar approach?
1) Create a copy of the active document.
2) Make changes to this copy of the document.
3) Embed the changed document in a dialog box.
4) After user is done previewing the new document, delete the modified copy.
You can display a document in a dialog box using an iframe. Dialog sizes of course can be changed from the example below. The the important part is https://docs.google.com/document/d/{id}/preview?authuser=0. I tacked the authuser=0 to give the hint to use the current users credentials. This isn't necessary, but it can prevent the account chooser box for popping up.
code.gs
function renderDocument(docId){
var html = HtmlService.createTemplateFromFile('dialog');
html.ID = id
var ui = DocumentApp.getUi();
ui.showModalDialog(html.evaluate().setWidth(800).setHeight(910), "html")
}
dialog.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<iframe frameborder="0" style="width:90%;height:900px" allowfullscreen="" src="https://docs.google.com/document/d/<?=ID?>/preview?authuser=0"></iframe>
</body>
</html>

Edit complete HTML of page in Drupal

We have our site running on Drupal. Now I have 2 landingpages: pages without menu's and a bit different in layout as the others. I want to edit the complete HTML of the pages in the Drupal-interface, so marketeers can easily add HTML-snippets (for testing etc), without using a developer.
How could I create an empty header and footer, and let the complete HTML be the content?
You could create a specific node type, and then use this function in your template.php :
<?php
function theme_preprocess_page(&$variables)
{
if (isset($variables['node']->type))
{
$nodetype = $variables['node']->type;
$variables['theme_hook_suggestions'][] = 'page__' . $nodetype;
}
}
It will allows you to create templates for pages (Drupal is only offering this possibility for the page content) based on node types using page--node-type.tpl.php, so that you'll be able to customize the entire page html instead of just the content.

Offline mobile application - should i be able to read in a localally stored JSON file?

My question is similar to the one here Trying to parse JSON file with jQuery but i don't seem to be able to adapt it.
I want to create an offline mobile app mainly using HTML5, CSS and JavaScript/Jquery
All the files in the app will be cashed I hope when I've it working
I had thought to created a JSON file containing some data about computer labs - eg open hours capasity that type of thing
{ "name":"Boole basement",
"location":"Main Campus",
"staffed":"Yes"}
And then read in the localy stored JSON file - parse it or whatever and then display each object in a new div. Initially I was just trying to get the data into one div. heck if I could get the contents of the JSON file to display I'd be delighted!
My HTML file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>test</title>
<script src="jquery-1.6.2.min.js"></script>
<script>
/* <![CDATA[ */
$(document).ready(function(){
var test =" ";
var filename = "test.json";
$.getJSON(filename, function(json){
$.each(json.labs, function(i, lab){
test = lab.name;
test+=" "+lab.location;
$('#space').append(test);
alert("Hi");
});
});
});
/* ]]> */
</script>
</head>
<body>
<h2>available labs:</h2>
<div id="space">some text</div>
</body>
</html>
PS Is what I've discribed even possible...
What you have described is entirely possible, yes. But your code needs work:
For example, your selector for space is incorrect (it's an ID in your mark-up, but you're using a class selector in your jQuery code).
(EDIT OK, I see you've edited your example code now).