I'm trying to create a gallery in Umbraco. All I want is to upload a bunch of pictures, write an optional description on each image, pull out the images with Razor, and finally place them on the site.
I can select many images using the Media Picker, then do this to pull them out:
var collection = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("images");
foreach (var image in collection) {
<img src="#image.Url" />
}
But if I use Media Picker, I cannot input a description on the image.
I have an idea, which is kind of stupid and slow: Create a child document type called Image on my Gallery document type. Each image content then has an image and a description. This would be a very annoying way to do it, though.
Is there a better way to do this?
If you go to the media section you can change the name of the images you have uploaded before and use it as the description. Or maybe add a description field on the mediatype image (if it's a long text).
<img src="#image.Url" alt="#image.Name" />
<img src="#image.Url" alt="#(image.GetPropertyValue<string>("description"))" />
Also there should be a flag in the DataType of the picker to add the "open" functionality to the picker, so you will be much faster in the process switching from content to the media tree
Related
I'm creating an MVC app. One of the pages requires a field containing a dynamic list of checkboxes. The actual number of checkboxes to display is controlled by the number of rows in a SQL table. Each row will be a checkbox. I've figured out how to do this and display them on the page using the following code. This example contains a dynamic list of currencies, with each currency represented by a checkbox. This example displays a label next to each checkbox describing what the currency is (e.g., USD). However, what's really wanted is to display an image (which would be contained in the model as a byte[] type) instead. I'm not sure how to accomplish this since MVC doesn't support anything like an #Html.ImageFor. This might be simpler than I'm making it out to be but I can't figure out how to place an image where the #Html.LabelFor current resides.
#for (int i = 0; i < Model.CurrencyList.Count; i++)
{
<div>
#Html.HiddenFor(x => x.CurrencyList[i].AdvertiserCurrencySupportId)
#Html.CheckBoxFor(x => x.CurrencyList[i].Checked)
#Html.LabelFor(x => x.CurrencyList[i].Checked, Model.CurrencyList[i].Currency)
</div>
}
You should just be able to use a basic image tag, inserting data where needed
<img src="#Model.CurrencyList[i].ImageUrl">
Since you've got the byte array, looks like you want to use inline images, so you should be able to do that with plain HTML:
<img src="data:image/png;base64,#Convert.ToBase64String(Model.CurrencyList[i].ImageBytes)">
But you're probably better off with a plain image pointing to a URL, since inline images can eat up a lot of bandwidth since you're pulling them every time the page loads, so you don't get any browser caching.
I'm able to upload images in the Media section in the admin panel. My question is: how do I use an updated image in a Partial View? I'm not asking about doing it programmatically. I have a very simple Partial View - code below:
<div>
<p style="text-align:center">Heading here</p>
<img/>
</div>
Please note that is all the code of the Partial View.
After uploading, I just want to add an image tag. The image name and ID will be available. Is there a way I can configure a wizard to select the image ?
If I have to do it manually by writing HTML, can you please share a sample of the required HTML image tag?
If I understood you correctly, you want to link to an image from your media library in your partial view.
If you have the image id, then you could simply do something like:
<img src="#Umbraco.Media(imageId).umbracoFile"/>
where "imageId" is the id of the image.
If you want to have it more configurable from your backoffice, you could add a property to your document type like "headerImage" and set the type of the property to "MediaPicker".
When you create a document of that type, you are now able to choose an image from your media library and assign it to the "headerImage" property.
To integrate this in your partial view, just access the image via the document property in your razor code:
#{
var imageId = #CurrentPage.headerImage;
var imageSource = #Umbraco.Media(imageId).umbracoFile;
<img src="#imageSource"/>
}
I'm afraid I've misunderstood something as the answer almost seem to simple. If you don't mind writing manual HTML after you've uploaded and you don't want to do it programatically, you can find the url of the published image in the properties tab of the image media node. Just put that in in
<img src="urlHere"/>
I need to show a drop down list with ability to select multiple items. I am able to bind this with a Dictionary object and it works fine with plain text values. However, i need to include img tags as well in the values.
This is basically a list of people along with their public profile picture. However, the list shows the html tags instead of showing the actual image.
Here is the razor code in my view:
#Html.ListBox("MyFriends", new MultiSelectList(Model.Connections.Distinct(), "key", "value"), new { #class = "list-item"})
The output is shown as:
<img src="http://localhost/api/person/1211/dp" title="avatar" /> John Smith
<img src="http://localhost/api/person/1212/dp" title="avatar" /> Person Two
<img src="http://localhost/api/person/1213/dp" title="avatar" /> Person 3
<img src="http://localhost/api/person/1214/dp" title="avatar" /> Rick Rude
But i want to actually show display picture followed by the name. Any solution?
The problem you are facing is not strictly connected with Razor or even with ASP.NET MVC.
It is connected with the fact that DOM prohibits you from placnig an tag directly inside tag (so it's an HTML-related constraint).
There is a possibility to use CSS styling to add images to your select list:
How to add a images in select list
This will though most probably not solve your problem because the styles are added statically, whereas your list is dynamic.
All in all I think you should consider using some alternative for Html.Listbox like for example jQuery Combobox.
In Drupal 7, I'm using the feeds module to pull in a bunch of books
That's all working perfectly. I am not setting up some views.
the feed pulls in an image url to on o my field like this [http://img.techbook.com/techwords/content/bk/blak/003834/full_image.jpg
but of course I need
<img src="http://img.techbook.com/techwords/content/bk/blak/003834/full_image.jpg" />
to display the image on the page
What is the best method of altering this fields' text, or is there a method so I can automatically format correctly. There are hundres of these, so manually do it is not an option
You can either use Feeds Tamper, which let's you manipulate the incoming feed data before it comes in (ie. wrap the url with img tags): http://drupal.org/project/feeds_tamper
OR
You can simply import the URLs into a field, and then render the URL with a template file that has the img tag wrapped around the field.
Like so: in node--content-type-name-here.tpl.php
<img src="<?php print render($content['field_url']); ?>" />
I would recommend the latter and only use Feeds Tamper for more serious manipulations.
I am new to MVC . I am creating a bookstore webpage application using aspx, and mvc. I have a database of books that says available or sold out. When a user clicks a dropdownlist they choose a book, it shows an image next to the book that is either supposed to show a green check mark if it is available or a red X if its not available. That information is all pulled from a database. My question is how do I change the image once a book becomes available. By the way my images are stored in my Content folder under imgs.
I have been searching for a while and haven't found a good answer. Any help or any websites you can suggest would be great thanks.
My image says this
<asp: Image ID = "Book_Availability" runat = "server" />
-----------Update----
When I mean change, I mean change the ImageURL so that it points to a different picture. On the server side I have value of 0 or 1. When I get a 1 i want to update the image URL to point to a different ImageURL from the controller, so that its from a X to a check mark. I am not sure how to accomplish this using MVC
Check out this link on Razor syntax. You could achieve what describe with something like:
#{
string availableImage = Url.Content("~/Images/availableImage");
string unavailableImage = Url.Content("~/Images/unavailableImage");
}
<img src= "#(Model.IsAvailable ? availableImage : unavailableImage)" alt="" />
You could perhaps add an click event handler onto the dropdown using jQuery. This could in turn do a $("#myimagewrapperexample").load() event against an action on some controller i.e BooksController
The action could return a partial view containing the books current image for example. Or it could return true, false depending on the books availability and you toggle the image in your javascript. All the action would need to be passed would be the id of the book and you could then look it up to determine it's status.
I've never used asp tags in a MVC project so can't comment on your usage there. AlexC suggestion of looking into the Razor syntax if your using MVC 3 is a good idea. Otherwise you might want to look into creating views using MVC 2. This Microsoft link might help you out on that front.