making an image link from a db asp.net mvc 4 - image

I have this foreach loop pulling images from my db :
`#foreach (var item in model)
<tr>
<td>
<img width="50" height="50" src="#Url.Action("GetImage", "Product", new { item.ProductId})"/>
</td>
...`
I tried to wrap it in an 'a' tag but all I get is 404's.
<img width="".../>
Any ideas?

an image with a hyperlink is what I'm trying to achieve. You click the
image and you're taken to the edit page.
Okay so suppose you get the image as shown in your question Product.GetImage and then the edit page is called by Product.Edit, you can have this:
<img src="#Url.Action("GetImage","Product")" />

Related

Generating html with CFSaveContent, images don't display

I'm trying to use cfsavecontent to send an html page (with CSS formatting). However, when I send the variable via cfmail, everything arrives fine, except the images.
<cfsavecontent variable="YourImg">
<table class="table_css">
<tr>
<td>
<p> your image is this:</p>
<img src="/imgs/image.jpg">
</td>
</tr>
</table>
</cfsavecontent>
<cfmail from="email#hotmail.com" to="email#gmail.com" subject="test email" type="html">
test:
<br /><br /><br />
#YourImg#
<br /><br /><br />
</cfmail>
This shows me the HTML table, formatted with the CSS, but the image looks like it is missing. Can anybody explain why?
<cfsavecontent> only saves the generated markup in between the tag into a string. You can <cfdump var="#YourImg#"> and see for yourself.
<cfdocument> can capture the image, but into a pdf file. Doc # https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-d-e/cfdocument.html
To attach files to the email, please look into <cfmailparam> # https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-m-o/cfmailparam.html
Example 2: This view-only example displays an image in the body of an
HTML message.
<cfmail type="HTML"
to = "#form.mailto#"
from = "#form.mailFrom#"
subject = "Sample inline image">
<cfmailparam file="C:\Inetpub\wwwroot\web.gif"
disposition="inline"
contentID="image1">
<p>There should be an image here</p>
<img src="cid:image1">
<p>After the picture</p>
</cfmail>

Grails image url loads but image doesn't load?

In grails, images url loads fine but image doesn't display...
def thumbphoto = {
response.setContentType('image/jpeg')
response.setHeader('Cache-control', 'no-cache')
if(params.id){
userId = params.id
}
if(params?.id != null && !(params?.id.empty)){
params.maxWidth?: 50.00
params.maxHeight?: 50.00
response.outputStream << imageProxyService.loadThumbnailImage(params.id, securityService.passwordEncoder(userId.toString()))
}
}
User has many images
This is the gsp view where i am trying to load and display images along with status updates.
<g:each in="${statusList}" status="i" var="status" status="i">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<tr>
<td>
<g:if test="${status.photo != null && !(status.photo.empty)}" >
<img id="profile_photo" src="${createLink(controller:'image', action:'thumbphoto', id:status.photo, params:[maxWidth:50.0,maxHeight:50.0,id:status.id])}" alt="" title="" />
</g:if>
<g:else>
<img id="profile_photo" src="${resource(dir:'images', file:'no_image_blue.gif')}" alt="No Image" width="50" height="50"/>
</g:else>
</td>
<td>${status.id}: ${status.message}</td>
</tr>
</tr>
</g:each>
Install Firebug, and go to the Net tab.
You should see all the HTTP requests and their statuses.
You're likely get a 404 for your image, check its location under your webapps folder...
Again Firebug will give you all the hints and solutions.
Use g:img.
<g:img dir="/image/showImage/9921355add3b115766ad41effdf000db9e461570.jpg" alt=""/>

xhtml2pdf does not show image always

I use xhmtl2pd tool to convert html to pdf. Here is a piece of my html
<tr>
<td style="width:10px;vertical-align:top">• </td>
<td style="padding:0 0 5px 0;width:200px;display:inline-block">
blah blah <br/>
<img src="images/little-gray-arrow.png" height="10" width="11" alt="blah" />
</td>
</tr>
The bizarre thing is if I remove the br tag then the image of little-gray-arrow.png never shows up. Put the br tag back, the image shows up in the "next" line.
I have tried with all options, padding, margin, and none works.
I also try to inline-displaying an image between text, and the image clock.png bottom half always get cut off, regardless what I tried.
<tr>
<td style="width:10px;vertical-align:top">• </td>
<td style="padding:0 0 5px 0;width:200px;">
Wait
<img src="images/clock.png" height="20" width="20" alt="20" />
minutes
</td>
</tr>
Does anyone know how to solve this problem and it is just the way xhmtl2pdf is.
Can the xhtml2pdf display image inline?
Thanks
Dont use absolute paths in url or src. Use fullpath like https://abcd.com/.../image.png . It worked for me
If you need render image format like GIF or PNG, you should install PIL library. The Python Imaging Library (PIL) is requred by ReportLab for handling PNG/GIF image.
Refer: Output image to pdf with xhtml2pdf

image onclick action to navigate to another jsp page using JSP

This is the code I have written to navigate to another jsp page onclicking the image. But, I didn't get the output. Please help me out.
<td align="center" >
<img src="image.jsp?imgid=<%=rs.getInt(1)%>" width="100" height="100" **onclick="ModelList.jsp"** >
Onclick is an event which expects an event handler (e.g a javascript function) to handle the even. so you can do something like this
onclick="window.href.location = ModelList.jsp"
the below alteration will work ..
<img src="image.jsp?imgid=<%=rs.getInt(1)%>" width="100" height="100" >

help me ! MVC and AJAX toolkit Editor in ASP.NET

I have view to use Ajax toolkit editor control.
View CreateProduct
<fieldset>
<legend>Product information</legend>
<table align="center">
<tr>
<td><label for="slogan">Slogan:</label></td>
<td><%= Html.TextBox("slogan")%></td>
</tr>
<tr>
<td><label for="content">Content :</label></td>
<td>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:Editor ID="content" runat="server" Height="300px" />
</td>
</tr>
</table>
</fieldset>
ProductController:
public ActionResult CreateProduct(string slogan, string content)
{
ProductDataContext data = new ProductDataContext();
PRODUCT p = new PRODUCT();
p.SLOGAN = slogan;
p.CONTENT = content;
data.AddProduct(p);
data.SubmitChanges();
return View();
}
When I added a product, just slogan was added, content was null.
I dont understand and how to repair it.
Help me, please!
Thanks so much!
It does not work this way. You are mixing ASP.NET WebForms with MVC. ID="content" only sets the server-side ID of the Editor control. Controller parameters however are mapped by form field names and in your case the name of the corresponding textarea is generated automatically. I'm not aware of any way you could normally change the name of a control rendered by ASP.NET. You can, however try the following:
<script type="text/javascript">
document.getElementById('<%= content.ClientID =>').name = 'content';
</script>
Put this at the bottom of your view. It might just work.
Keep in mind that even if it works, the above is a dirty hack. The right approach in an MVC project would be to initialize the Editor control using just client scripting. This is not always easy but doable. For reference, try looking at the source of this page:
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/htmleditor/OtherSamples/ClientSide.htm

Resources