As the introduction goes I am a new developer who has currently started using Umbraco. As far as it goes i agree its a powerful CMS for the right client , but the code is dispersed throughout the internet and the explanation is too long or difficult for me to understand. i.e the reason for this thread ( hope this is not a repeated question, if so i hope i am directed to the code).
firstImage and secondImage is the property Alias for the images in the document type, similar to the content
Format to render the data from partial view to the blog page inside appropriate div's
First image (float left) Content ( float right)
Second image (float left) SecondContent ( float right)
i want to write a IF statement saying if there is no image in imageSecond i want to hide the image div and display only the secondContent .
Its rendering @Umbraco.Field("secondContent")twice
i.e
<img src="@imageSecond.umbracoFile">
@Umbraco.Field("secondContent")
@Umbraco.Field("secondContent")( and a weird right side empty space (equal to the image box space) since there is no image to display on this line. )
Also when there is no image its displaying a weird line on the page and on inspecting the element it says
<img src="unknown">.
@Umbraco.Field("secondContent")
@Umbraco.Field("secondContent") ( weird right space equal to the imagebox space).
Also i tried doing that before and getting the following error when i have second image to be posted.
Server Error in '/' Application.
Operator '!=' cannot be applied to operands of type 'Umbraco.Web.Models.DynamicPublishedContent' and 'string'
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: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Operator '!=' cannot be applied to operands of type 'Umbraco.Web.Models.DynamicPublishedContent' and 'string'
Source Error:
Line 20:
Line 21:
Line 22: @if (imageSecond != null && imageSecond != "")
Line 23: {
Line 24:
hope this gets resolved cause its eating me, the theory behind is right , but the code is damm adamant to work, hope i am not missing any hidden @using or @inherits for this view page.
Also the structure of the page is :-
the main page having all the render action event calling the partial page ( eg:- @{Html.RenderAction("Render_Search", "Home");} )
there is a controller which creates the RenderAction method which is simply the file path of the partial .
* public ActionResult RenderSearch()
{
return PartialView("~/Views/Partials/Home/Search.csHtml");
}*
and the partial mentioned above which has all the html and code to get the data from the admin panel.
It kinda worked but its still leaving a right hand empty space when there is no image ,
also can you give a bit of explanation why it worked in properly executing the if else statement, please ?
because, what i can't process it when i am making the image second to string why does it need to call imagesecond.ToString again in the IF statement.
In relation to the above:-
And i have seen many different variety of codes with different variety to get the same result. Is this code restricted to media picker alone or can i use it for multiple media picker and put a for each loop to call one image and the rest follows.
earlier code
@{
var image = Umbraco.Media(@Umbraco.Field("firstImage").ToString());
var imageSecond = Umbraco.Media(@Umbraco.Field("secondImage").ToString());}
Making a If statement in U 7.7.4
Hi,
As the introduction goes I am a new developer who has currently started using Umbraco. As far as it goes i agree its a powerful CMS for the right client , but the code is dispersed throughout the internet and the explanation is too long or difficult for me to understand. i.e the reason for this thread ( hope this is not a repeated question, if so i hope i am directed to the code). firstImage and secondImage is the property Alias for the images in the document type, similar to the content
Format to render the data from partial view to the blog page inside appropriate div's
First image (float left) Content ( float right) Second image (float left) SecondContent ( float right)
i want to write a IF statement saying if there is no image in imageSecond i want to hide the image div and display only the secondContent .
Its rendering
@Umbraco.Field("secondContent")
twice i.e<img src="@imageSecond.umbracoFile"> @Umbraco.Field("secondContent") @Umbraco.Field("secondContent")
( and a weird right side empty space (equal to the image box space) since there is no image to display on this line. ) Also when there is no image its displaying a weird line on the page and on inspecting the element it says<img src="unknown">. @Umbraco.Field("secondContent") @Umbraco.Field("secondContent")
( weird right space equal to the imagebox space).Hi,
Looks like you're new to Razor C#.
I think what you're trying to do needs you to change:
to this
Yes i am .
Also i tried doing that before and getting the following error when i have second image to be posted.
Server Error in '/' Application.
Operator '!=' cannot be applied to operands of type 'Umbraco.Web.Models.DynamicPublishedContent' and 'string'
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: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Operator '!=' cannot be applied to operands of type 'Umbraco.Web.Models.DynamicPublishedContent' and 'string'
Source Error:
Line 20:
*[RuntimeBinderException: Operator '!=' cannot be applied to operands of type 'Umbraco.Web.Models.DynamicPublishedContent' and 'string'] CallSite.Target(Closure , CallSite , Object , String ) +182 System.Dynamic.UpdateDelegates.UpdateAndExecute2(CallSite site, T0 arg0, T1 arg1) +450 CallSite.Target(Closure , CallSite , Object , String ) +241 ASP.PageViewsPartialsAboutaboutContentcsHtml.Execute() in d:\Mahesh\New IMG\IMG Reliance\Views\Partials\About\aboutContent.cshtml:22 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +90 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +235 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107 Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +113 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +290 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 filters, ActionResult actionResult) +52 System.Web.Mvc.Async.<>cDisplayClass2b.1c() +173 System.Web.Mvc.Async.<>cDisplayClass21.1e(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.Controller.[HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.] System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3474692 System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +76 System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +29 System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +24 System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +463 System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName) +35 ASP.PageViewsAboutcshtml.Execute() in d:\Mahesh\New IMG\IMG Reliance\Views\About.cshtml:47 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105 System.Web.WebPages.StartPage.RunPage() +17 System.Web.WebPages.StartPage.ExecutePageHierarchy() +64 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +235 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107 Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +113 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +290 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +52 System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12 System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +22 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9987265 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155*hope this gets resolved cause its eating me, the theory behind is right , but the code is damm adamant to work, hope i am not missing any hidden @using or @inherits for this view page.
Also the structure of the page is :-
the main page having all the render action event calling the partial page ( eg:- @{Html.RenderAction("Render_Search", "Home");} )
there is a controller which creates the RenderAction method which is simply the file path of the partial . * public ActionResult RenderSearch() { return PartialView("~/Views/Partials/Home/Search.csHtml"); }*
and the partial mentioned above which has all the html and code to get the data from the admin panel.
The quick fix is :
@if (imageSecond != null && imageSecond.ToString() != "")
To be honest I'm not sure it's required but I don't ever use the Dynamic models but it should at least get you working.
Thanks Steve,
It kinda worked but its still leaving a right hand empty space when there is no image , also can you give a bit of explanation why it worked in properly executing the if else statement, please ?
because, what i can't process it when i am making the image second to string why does it need to call imagesecond.ToString again in the IF statement.
In relation to the above:- And i have seen many different variety of codes with different variety to get the same result. Is this code restricted to media picker alone or can i use it for multiple media picker and put a for each loop to call one image and the rest follows.
earlier code
@{ var image = Umbraco.Media(@Umbraco.Field("firstImage").ToString()); var imageSecond = Umbraco.Media(@Umbraco.Field("secondImage").ToString());}
is working on a reply...