日期:2014-05-17  浏览次数:20464 次

MVC中的方法可以写在前台页面吗?这个问题怎么解决?
要实现的是,如果数据库没有图片地址,显示默认。主要看那个getUrl()方法,在asp.net MVC里怎么不能这么写?报错呢

 @{ public static
              string getUrl(string Url)//处理url
                   {
                       if (string.IsNullOrEmpty(Url))
{
                           return "/uploads/noproduct.png";
 
}
                       
                       return Url;
                   }
                    
        }


<div class="c-prolistbox">
                    <ul>
                        @foreach (var item in (List<ProductService.Model.ProductModel>)ViewBag.modelList)
                        {
                            <li>
                                <div class="lproot">
                                    <div class="photoimgcc">
                                        <a href="@Url.Content("~/Show/Detail?id")=@item.Id" target="_blank">
                                            <img src="@getUrl(item.Url)" width="220" height="220" /></a>
                                    </div>
                                    <div class="show-item-meta">
     &nbs