0

I am trying to show products fetched from database by creating a user control ProductBox and inside it setting the parameters to be shown from the Model. But the following block of code shows the unhandled exception : strUrl doesn't exist in the current context.

I am totally new to MVC. Can you help me spot where the parenthesis is missing? Here is my code from ProductBox user control.

<%@ Control Language="C#"  Inherits="System.Web.Mvc.ViewUserControl<TSRApp.UI.Models.ProductBox>" %>
<%@ Import Namespace="TSRApp.UI.Helpers" %>
<%@ Import Namespace="TSRApp.Contracts.Common.OperationalContracts" %>

<% string strStartTag = "<div class=\"fl book-shaddow\">";
string strEndTag = "</div>";
if (Model.IsFeatured)
{
   strStartTag = "<li " + Model.LiID + " >";
   strStartTag = strStartTag + "<div class=\"book-shaddow\">";
   strEndTag = "</div></li>";
}
if (Model.ProductName.Length > 40)
{
   Model.ProductName = Model.ProductName.Substring(0, 37) + " ...";
}
if (string.IsNullOrEmpty(Model.ProductZoomImage))
{
   if (!string.IsNullOrEmpty(Model.ProductSmallImage))
   {
       string strZoomImage =    Model.ProductSmallImage.Substring(Model.ProductSmallImage.IndexOf("src=")).Replace("src=\"", "");
       strZoomImage = strZoomImage.Substring(0, strZoomImage.IndexOf("\""));
       Model.ProductZoomImage = strZoomImage;
   }
   else
   {
       Model.ProductZoomImage = Model.ProductSmallImage.Replace("~", "");
   }
}
string strURL = string.Empty;
strURL = "/Product/Information/" + Model.ProductCode;

%>
<%= strStartTag %>
<% if(UiHelper.GetDeviceID()!=4)
{ 
%>
<a href="<%=strUrl %>"></a>
<%
}
%>
<% if (!string.IsNullOrEmpty(Model.ProductSmallImage))
  { 
%>
<%= Model.ProductSmallImage%>
<% 
  }
%>
<img src="<%=Model.ProductSmallImage %>" alt="<%= Model.ProductName %>" 
style="height: 200px; width: 170px" />

<%= strEndTag %>

Kindly help me fix this issue. Thanks.

1 Answer 1

1

C# is case-sensitive. Change <%=strUrl %> to <%=strURL %> and you should be good to go.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. That solved my issue. Changed strURL to strUrl all through.
Hi user3064858. Could you please accept this as answer. Its a gesture for people who really help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.