title: Error Help: Out Of Bounds
body: <pre><code>@foreach (var item in Model)
  {
      &lt;li&gt;
          &lt;div class="lnewsblock"&gt;
              &lt;p class="newsthumb"&gt;
                  &lt;img src="@Html.Raw(item.ShortImage)" width="90" height="71" alt="" /&gt;&lt;/p&gt;
              &lt;p class="datetxt"&gt;@Html.Raw(item.Date.Value.ToString("ddd MM.dd.yyyy"))&lt;/p&gt;
              &lt;h2&gt; &lt;a href="/resources/newsdetail?id=@Html.Raw(item.ID.ToString())"&gt;@Html.Raw(item.Title)&lt;/a&gt;&lt;/h2&gt;
              &lt;p class="greytxt"&gt;@Html.Raw(item.Description.Left(125))&lt;a href="/resources/newsdetail?id=@Html.Raw(item.ID.ToString())"&gt; more&lt;/a&gt;&lt;/p&gt;
          &lt;/div&gt;
      &lt;/li&gt;
  }
  </code></pre>
  
  <p>The above code is causing a couple of issues.  You will notice that it is pulling  ShortImage which is fine. However, if there <strong>isn't an image to pull</strong>, this produces an error.  How would I fix the code to account for this?</p>
  
  <p>Secondly, when it pulls the item description,  It tries to pull the first <code>125</code> characters. So <strong>if the description is too short, this also produces an error.</strong>  How would I structure the code to account for this?</p>
  
  <pre><code>Server Error in '/' Application.
  Index was outside the bounds of the array.
  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.IndexOutOfRangeException: Index was outside the bounds of the array.
  
  Source Error:
  
  An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
  
  Stack Trace:
  
  
  [IndexOutOfRangeException: Index was outside the bounds of the array.]
     SitefinityWebApp.Mvc.Models.NewsModel.RetrieveCollectionOfNews(NewsType ShowType) in D:\SVN\LbyEgglw\LbyEgglw.WebApp\Mvc\Models\NewsModel.cs:53
     SitefinityWebApp.Mvc.Controllers.NewsController.Index() in D:\SVN\LbyEgglw\LbyEgglw.WebApp\Mvc\Controllers\NewsController.cs:29
     lambda_method(Closure , ControllerBase , Object[] ) +43
     System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +248
     System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
     System.Web.Mvc.&lt;&gt;c__DisplayClass15.&lt;InvokeActionMethodWithFilters&gt;b__12() +125
     System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640
     System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +312
     System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +691
     Telerik.Sitefinity.Mvc.ControllerWrapper.Execute() +133
     Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy.ExecuteController() +2620
     System.Web.UI.Control.PreRenderRecursiveInternal() +113
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Control.PreRenderRecursiveInternal() +222
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4201
  
  
  Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272 
  </code></pre>