I think if you make your Partial View inherit UmbracoViewPage
@inherits UmbracoViewPage<MySite.Models.MyModel>
@{
// I'm not sure how you are deciding which image to show.. eg on a picker?
myImage = Umbraco.Media(123);
}
@using (Html.BeginUmbracoForm<MySite.Controllers.MySurfaceController>("SubmitForm", "My", FormMethod.Post))
{
**I want to add image here**
if (myImage!=mull){
exampe: <img src="@myImage.Url" />
}
}
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1003: Syntax error, ',' expected
Source Error:
Line 34:
Line 35:
**Line 36: public class _Page_Views_Partials_MyPartialView_cshtml : UmbracoViewPage<model MySite.Models.MyModel> {**
Line 37:
Line 38: #line hidden
Ok, I removed "model" from the inherit, a typo maybe?
But.... When I added @Html.AntiForgeryToken() it gave me an error...
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 5: @using (Html.BeginUmbracoForm<MySite.Controllers.MySurfaceController>("SubmitForm", "My", FormMethod.Post))
Line 6: {
**Line 7: @Html.AntiForgeryToken()**
Line 8: **I want to add image here**
Line 9: if (myImage!=mull){
The error is on line 7 (bold doesn't seem to work inside the code sample...
EDIT: Never mind, it worked. I forgot to change the ID for the media ... whoops... :-D
I think I understand you correctly... but the Partial View will be on a page in Umbraco somewhere, so I think on the document type for that page - or if this is a 'global image' on the document type for the homepage - create a new property called 'Form Image' or similar and make the property a 'Media Picker'
Then in the backoffice of Umbraco 'pick' the image that you want to display on the form and publish the page.
Then in your Partial View you can read the picked image and display it accordingly eg
@inherits UmbracoViewPage<MySite.Models.MyModel>
@{
var formImage = Model.Value<IPublishedContent>("formImage", fallback: Fallback.Ancestors);
}
@using (Html.BeginUmbracoForm<MySite.Controllers.MySurfaceController>("SubmitForm", "My", FormMethod.Post))
{
**I want to add image here**
if (formImage!=mull){
<img src="@formImage.Url" />
}
}
the fallback to ancestors, means Umbraco will look for a media picker with alias "formImage" all the way up the content tree to the homepage - so if the image is the same across all forms, you could set it globally on home.
Error, Model doesn't have a definition for 'Value' (typo maybe?)
EDIT: Here is the exact error, it might help.
'MyModel' does not contain a definition for 'Value' and the best extension method overload 'PublishedElementExtensions.Value<IPublishedContent>(IPublishedElement, string, string, string, Fallback, IPublishedContent)' requires a receiver of type 'IPublishedElement'
Need help adding an image from the MEDIA folder to a partial view
I need help :-)
Here is my partial view:
Hi Edgar
I think if you make your Partial View inherit UmbracoViewPage
or something similar.
regards
Marc
Thank you for your reply. I got an error:
Ok, I removed "model" from the inherit, a typo maybe?
But.... When I added @Html.AntiForgeryToken() it gave me an error...
The error is on line 7 (bold doesn't seem to work inside the code sample...
EDIT: Never mind, it worked. I forgot to change the ID for the media ... whoops... :-D
Hi Edgar
Sorry for the typo! in the <> brackets.
Glad you got it working.
regards
Marc
Thank you.
One last question. How can I find the MediaID using it's "name" or any other property? That way I can just use the "name" of the image....
Thanks.
Hi Edgar
I think I understand you correctly... but the Partial View will be on a page in Umbraco somewhere, so I think on the document type for that page - or if this is a 'global image' on the document type for the homepage - create a new property called 'Form Image' or similar and make the property a 'Media Picker'
Then in the backoffice of Umbraco 'pick' the image that you want to display on the form and publish the page.
Then in your Partial View you can read the picked image and display it accordingly eg
the fallback to ancestors, means Umbraco will look for a media picker with alias "formImage" all the way up the content tree to the homepage - so if the image is the same across all forms, you could set it globally on home.
regards
Marc
Thanks.
Error, Model doesn't have a definition for 'Value' (typo maybe?)
EDIT: Here is the exact error, it might help.
is working on a reply...