Asp.net mvc 用户控件中的MVC代码给出错误:
我试图通过创建一个用户控件ProductBox并在其中设置要从模型显示的参数来显示从数据库获取的产品。但是下面的代码块显示了未处理的异常:strUrl在当前上下文中不存在 我对MVC一无所知。你能帮我找出括号缺的地方吗? 这是我的ProductBox用户控件代码Asp.net mvc 用户控件中的MVC代码给出错误:,asp.net-mvc,c#-4.0,viewusercontrol,Asp.net Mvc,C# 4.0,Viewusercontrol,我试图通过创建一个用户控件ProductBox并在其中设置要从模型显示的参数来显示从数据库获取的产品。但是下面的代码块显示了未处理的异常:strUrl在当前上下文中不存在 我对MVC一无所知。你能帮我找出括号缺的地方吗? 这是我的ProductBox用户控件代码 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TSRApp.UI.Models.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 %>
40)
{
Model.ProductName=Model.ProductName.Substring(0,37)+“…”;
}
if(string.IsNullOrEmpty(Model.ProductZoomImage))
{
如果(!string.IsNullOrEmpty(Model.ProductSmallImage))
{
字符串strZoomImage=Model.ProductSmallImage.Substring(Model.ProductSmallImage.IndexOf(“src=”).Replace(“src=\”,”);
strZoomImage=strZoomImage.Substring(0,strZoomImage.IndexOf(“\”);
Model.ProductZoomImage=strZoomImage;
}
其他的
{
Model.ProductZoomImage=Model.ProductSmallImage.Replace(“~”,”);
}
}
string strURL=string.Empty;
strURL=“/Product/Information/”+Model.ProductCode;
%>
“alt=“”
style=“高度:200px;宽度:170px“/>
请帮我解决这个问题。
谢谢。C#区分大小写。将
更改为
,您应该可以开始了。谢谢。这解决了我的问题。将strURL更改为strURL。嗨,用户3064858。您能接受这个答案吗。这是对真正帮助您的人的一种姿态。