Razor - How do I output the current cshtml filename - asp.net-mvc

For debugging purposes, I would like to output an HTML comment indicating the filename of the current cshtml file at the beginning and end of every cshtml file.
For example, I'd like so that when I view the source of the generated webpage, I would see something like this:
<!-- BEGIN _Layout.cshtml -->
... some headings and such ...
<!-- BEGIN About.cshtml -->
... generated content from the About.cshtml ...
<!-- END About.cshtml -->
... some footers and such ...
<!-- END _Layout.cshtml -->
I'm fairly new to this platform, so I'm not even sure what the right terminology is for this, let alone where in the API to look. I'm hoping that at the very least I can edit all of my cshtml files and reference some object at runtime that contains the filename as a property, in a syntax similar to:
<!-- BEGIN #Object.OptionalProperty.OptionalSubProperty.Filename -->
Or, alternatively, a way to modify the rendering engine so that it automatically does this at the beginning and end of every rendered file.
Thank you so much for your time and responses.

Related

Collapse sections in cshtml view

Is there a way to collapse a razor code block or section in a cshtml file?
As you can in the image above, the div is collapsable but not the section or the code block.
Any ideas?
You could try this Visual Studio extension:
https://visualstudiogallery.msdn.microsoft.com/bc07ec7e-abfa-425f-bb65-2411a260b926
One of the reviews claims that it allows you to collapse #helper and #section code blocks in MVC4 views but it doesn't seem to work for everyone.
You can add a section in CSHTML files like this:
<!-- #region name -->
wrapped content...
<!-- #endregion -->
This works at least since VS2015:
Note: You can even wrap the HTML comments in CSHTML comments (#* ... *#)

Dart: dynamic redirection without reload

Please note I'm not interested in a Polymer-, Angular- or route-based solution here. I'm trying to learn "pure" Dart here, and while I'll likely switch to using one of those frameworks down the road, I need to have a good understanding of the fundamentals first.
In Dart, is it possible to download a whole bunch of HTML "snippets" (see below) all at once (at app startup), and then load them into the browser (either the entire window or just inside a particular <div> element, etc.) dynamically?
For instance, my HTML file might have a <div> element:
<body>
<!-- lots of HTML -->
<div id="container"></div>
<!-- more HTML -->
</body>
And I would like to download two "snippets" (DOM subtrees, HTML templates) of HTML, and dynamically load either one of them into the container div tag. Perhaps one of the snippets looks like this:
<h1>I'm Snippet #1!!!</h1>
<input type="button" name="redPillButton" value="Red Pill!" />
And another snippet my look like:
<h1>I'm Snippet #2!!!</h1>
<input type="button" name="bluePillButton" value="Blue Pill!" />
Can the two snippets be inside their own HTML file, or do I have to put them inside one big file and extract out the "snippet" that I want to load? Either way, how do I accomplish this in a Dart web app?
You can keep each parts in their own file and load them like that :
HttpRequest.getString("part.html").then((html) {
querySelector('#container').innerHtml = html;
});

Where can I find (and change) the markup used by "render 'flashes'"?

This is my first project using Ruby on Rails and I'm working on the front-end code; the back-end developer is new to rails too. One template includes the code render 'flashes', which is triggered when there is an error on a form submission; but the markup it generates is messed up, and I'd like to fix it. Here's an example. The <!-- comments --> are mine:
<div id="flash">
<div class="wrapper">
<div title="Error" class="error"></div> <!-- Empty div -->
<p>Please enter a valid email</p> <!-- p element sibling of div.error -->
</div> <!-- Closes div.wrapper -->
</div> <!-- Closes div#flash -->
</div> <!-- Extra /div closes parent div -->
I would prefer to use one div for the message, but the biggest problem is the extra closing div tag at the end, which closes a parent division, messing up the layout.
I see that the error message is defined in the controller as flash[:error] = "Please enter a valid email", but I don't know where rails is getting this bogus markup. Is there a _flashes partial I can edit to fix this problem? I've pored over the project's filesystem, and it's not clear to me where this markup lives.
There is no _flashes.html.erb file in the Rails source. If you're seeing
render 'flashes'
in your application, you or some generator you ran put it there. Look through the files in app/views/ for one called _flashes.html.erb that contains the markup you provided in your Question. Once you find that file you should be able to modify it however you need to fix your broken HTML issue.
If you can't find it there, look at your list of gems in your Gemfile, specifically for one that relates to theming/templating. It's possilbe you've included a gem that contains this template file (though much less likely than the file existing in app/views/).

Raw Mako template included in another in Pylons

I'm trying to include a raw Mako template to make it appear in a textarea with Pylons.
In Pylons, I know I can include one Mako template in another like this:
<html>
<body>
Here is some HTML. Now, I want to include a template.
<%include file="${c.a_mako_template}" />
</body>
</html>
Is there a way that I can do the same thing, but have the template appear as raw markup rather than passing through Mako renderer? I'm imagining something like:
<%include file="${c.a_mako_template}" render="false" />
If that sort of thing is impossible, is the best route to write a Pylons controller that does the inclusion at a later stage?
Could I somehow wrap the file to be included in <%text> tags on the fly, perhaps using <% def>?
I've figured out a sort of workable solution. It still has one rough bit, but it works.
<%
path = '/path/to/file/'
f = open(path + c.sourcefile, 'r')
text_to_edit = f.read()
f.close()
%>
<textarea id="code">
${text_to_edit}
</textarea>
The first part is just a chunk of Python embedded in the template. It opens the file and extracts the text, thereby bypassing Mako.
The rough bit is the hardcoded path. I'll have to pass that as c.path, or something like that.

Determine an absolute url to a resource using vbscript/classic asp

I've created a pseudo user control for a site written in classic asp. The control is simply an asp page (with full HTML headers and body) that resides within an iframe in the parent page. The point was to create an AJAX-like interface for uploading files asynchronously (the parent page contains a large form and I didn't want to have to upload the files and submit the rest of the form at the same time).
The problem is, I'm running into a lot of issues with relative urls being used in the iframe page/user control. Depending on what page the iframe is a child of, the relative url base location seems to change according to the directory that particular page is in.
Example:
www.website.com/directory1/application1.asp
...
<form>
<input>
...
<iframe src="../controls/FileUpload.asp"/>
...
</form>
...
www.website.com/directory1/directory2/application2.asp
...
<form>
<input>
...
<iframe src="../../controls/FileUpload.asp"/>
...
</form>
...
www.website.com/controls/FileUpload.asp
...
<form method="post" enctype="multipart/form-data" action="FileUpload.asp"><!--problem here-->
<input type="file">
<input type="submit"/>
</form>
The iframe src paths work correctly (notice the one that's buried a directory deeper has an extra double dot). But in the code for the FileUpload.asp page, relative URLs don't work consistently. The URL I have in the action attribute for the form tag works if you simply load the page as-is, not in an iframe of another page. You can change it to "../controls/FileUpload.asp" and it will work on the first application page, but you have to add another "../" for it to work on the second application page.
I was wondering if maybe there's a way with vbscript to find the absolute URL to a certain file. I do use an include file into which I could hard-code this, but I'd rather not if that's possible. Any other ideas?
You could also just put in an absolute path from the root such as
action="/controls/FileUpload.asp"
I'm not sure if you are perhaps looking for
<%
Response.Write Server.MapPath("./foo.txt")
%>
Some usefull code from Thorarin
that I just saw in a different post
Look for ThisPage() Function

Resources