How to Display stored image in html in database into view with razor engine - asp.net-mvc

I have a section that saves html created with an html editor into a database in the site control panel.
in my html if I insert image with this address "image/Picture1.jpg" using the html editor if there is a image stored at mysite.com/image/picture1.jpg.
Now in a view(razor) I display the stored html content from the database with System.Web.HttpUtility.HtmlDecode or #Html.Raw(item.Content). if this content is shown the in home page like mysite.com it works correctly.
but, if it show it in other area or controller or action the image doesn't show. Because in those areas (like mysite.com/desktop) the image address changes to mysite.com/desktop/image/picture1.jpg.
How do I display this html content without this problem?

The images will always be relative to the page that displays them as you are using a relative URL.
Unless they have an absolute URL mysite.com/image/picture1.jpg or a root-relative URL /image/picture1.jpg in the HTML it will not work.
A: You need to enter the URL in the HTML editor as either absolute
mysite.com/image/picture1.jpg
or root-relative:
/image/picture1.jpg
In both cases the browser will search from root of the website, and not just relative to the current page.

Related

How to get form values in browser to watir webdriver

I have installed my application and it is running on following URL
http://localhost:3000
Above URL will the load form with some fields, Then I will the fill the data in the required field and then submit form. My div element will displayed at the bottom of the page. Picture will be displayed inside the iframe with in the div element.
User will the above URL and then submit form. After submitting the form, Picture should be downloaded into their local machine.
Right I am calling the following line after form submission, how can I get the existing page into the browser object and download screenshot?
browser = Watir::Browser.new
b.div(:id => "phone_shell").screenshot("/home/user/Documents/preview.png")
I found few problems in your code
screenshot method is not available for element object, it's available for browser object and also you need to call the method save to save the file in the destination folder. So write the following code, it would work.
Code to get the html of the page
b.html
Code to take the screenshot
b.screenshot.save("/home/user/Documents/preview.png")
Now this will save the image in the destination folder.

MVC Partial View - Link to location on page

Let's say I have an Html page with divs.
If I want to link to a specific location on that page, I can create a url like http://www.example.com#mylocation
Now let say I'm calling that page as a partial view instead. Can I still get to those page locations?
#Html.Partial("_MyPartialView")
Yes, you can still get to those page locations.
Rendering a partial doesn't do anything special; the final HTML is the same as if you pasted the partial's contents into the same place. (You can even access ViewBag and it should have the same variables in it from the controller.)
If you view the final page source, you'll still see your HTML anchors. You can manually append #mylocation in your browser URL and see that it still works.

Generate Text (.txt) file for Data displayed in GSP

I have a Grails app developed in 2.3.6
There's a GSP file with HTML and CSS elements in it, and that displays data in multiple tables with headers.
I want this data to be saved into a text file and save it. So basically what i want to do is, there will be a Export button in this GSP page, and when user clicks on it, it will download the text file with all the data from that GSP.
What i tried so far?
def textFile = {
response.setHeader('Content-Disposition', 'Attachment;Filename="textFile.txt"')
render view: 'textFile', contentType: 'text/plain'
}
The problem with above is, it saves not just data, but also HTML & CSS elements.
I don't want any HTML or CSS in the text file. Only data from GSP is needed.
Is there a simple way of doing it.
the answer is simple - you need another view withouth the html and css parts.
The rest of your code looks good. But Grails itself does not convert your view, it just sends the content type to the browser and the browser tries to diesplay the data according to the content type.
If you don't want to write a new view (in most cases, writing the new view is dead simple), you could write your own converter (something which strips the HTML and CSS from your file) by creating an afterView-Filter: http://grails.github.io/grails-doc/2.4.0/guide/single.html#filters
Hope that helps

How to ensure that all the non-origin href links open in a new tab?

I have a html content stored in backend, which may have certain anchor tags with href links, when rendering them I build a custom NodeValidator and then bind the value using a angular.dart decorator. Some of the href links points to outside my domain, I want to make sure that target='_blank' is added as attribute to such anchor tags so that browsers open the link in a new tab. Can this be taken care of by some UriPolicy or custom NodeValidator?

Adding a trailing slash after url moves the box below the menu & logo over it

I am using codeigniter.
My products page shows all the products we have and then users can click on each product_name to get more details about that particular product. So, I have declared products as the class and product_name as a function within the product class - so I could get the url www.company.com/products/product_name.
When I go to www.company.com/products everything is fine but if I add a trailing slash so it looks like www.company.com/products/ my window underneath the logo and menu moves over it hiding both the logo and menu. The same happens when I go to www.company.com/products/product_name.
How can I make sure that the window below does not hide when I add trailing slashes or when I go to product_name pages.
Any help would be appreciated.
The problem is that you have specified a relative path for your images. You need to make them absolute, or at least relative to the current location. That is to say, if you change your image path from:
<img src="images/obsia.png">
to
<img src="/images/obsia.png">
or
<img src="http://www.obsia.com/images/obsia.png">
Your problem will be solved.
The reason this is happening is because the path to the images is determined by the base URL. When you are at http://www.obsia.com or http://www.obsia.com/products, your base URL is http://www.obsia.com.
To the browser then images/obsia.png is rendered as http://www.obsia.com/image/obsia.png, which your server interprets as wwwroot/images/obsia.png and the relative link works.
However, if you do http://www.obsia.com/products/ your base url is http://www.obsia.com/products and the relative path for your images changes from http://www.obsia.com/images/obsia.png to http://www.obsia.com/products/images/obsia.png.
Your server interprets this as , which your server interprets as wwwroot/images/products/obsia.png, which is not a valid path. The server returns a 404 --resulting in broken images.
You can see this if you use Firebug's .Net panel. The request for your logo returns:
GET obsia.png
http://www.obsia.com/products/images/obsia.png
404 Not Found
obsia.com
539 B

Resources