user3064858
user3064858

Reputation: 1

MVC code in User Control giving error:

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.

Upvotes: 0

Views: 50

Answers (1)

TLS
TLS

Reputation: 3150

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

Upvotes: 1

Related Questions