ユーザー コントロール ProductBox を作成し、その内部でモデルから表示されるパラメーターを設定することにより、データベースから取得した製品を表示しようとしています。しかし、次のコード ブロックは未処理の例外を示しています。strUrl は現在のコンテキストに存在しません。
私はMVCにまったく慣れていません。括弧が抜けている場所を見つけるのを手伝ってもらえますか? ProductBox ユーザー コントロールからの私のコードを次に示します。
<%@ 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 %>
この問題を解決するのを手伝ってください。ありがとう。