Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 什么';这个代码怎么了? @使用System.Configuration @使用UI.AuctionService @使用UI.Common @使用UI.Helpers @模型UI.Models.AuctionFrontendListViewModel @{ ViewBag.Title=“拍卖清单”; } @模型名称 形象 类型 拍卖所有权 开始 末端 特色 投标计数 创建时间 @foreach(模型拍卖中的var拍卖) { var type=string.Empty; 如果(拍卖。拍卖是拍卖) { type=“最低唯一赢家”; } else if(auction.auction为电子拍卖) { type=“最高胜利”; } 字符串imagesFolderPath=HttpContextHelper.GetPathInServer(ConfigurationManager.AppSettings[“imagesFolderPath]”); string itemImagesFolderPath=Path.Combine(imagesFolderPath,ImageType.Item+@“\\\”+auction.auction.InventoryReference); string chosenImage=string.Empty; if(Directory.Exists(itemImagesFolderPath)) { string[]files=目录.GetFiles(itemImagesFolderPath); 如果(files.Length>0) { chosenImage=文件[0]; } } @类型 @DisplayFor(modelItem=>auction.auction.Title) @DateTimeHelper.LocalDateTime(auction.auction.Starts) @DateTimeHelper.LocalDateTime(auction.auction.Ends) @DisplayFor(modelItem=>auction.auction.IsFeatured) @DisplayFor(modeleItem=>auction.auction.BidCount) @DateTimeHelper.LocalDateTime(auction.auction.AddedDate) @ActionLink(“细节”,“细节”,新的{id=auction.auction.id}) } @PageLinks(Model.pagininfo,x=>Url.Action(Model.Action,new{page=x}))_C#_Asp.net Mvc 3_Razor - Fatal编程技术网

C# 什么';这个代码怎么了? @使用System.Configuration @使用UI.AuctionService @使用UI.Common @使用UI.Helpers @模型UI.Models.AuctionFrontendListViewModel @{ ViewBag.Title=“拍卖清单”; } @模型名称 形象 类型 拍卖所有权 开始 末端 特色 投标计数 创建时间 @foreach(模型拍卖中的var拍卖) { var type=string.Empty; 如果(拍卖。拍卖是拍卖) { type=“最低唯一赢家”; } else if(auction.auction为电子拍卖) { type=“最高胜利”; } 字符串imagesFolderPath=HttpContextHelper.GetPathInServer(ConfigurationManager.AppSettings[“imagesFolderPath]”); string itemImagesFolderPath=Path.Combine(imagesFolderPath,ImageType.Item+@“\\\”+auction.auction.InventoryReference); string chosenImage=string.Empty; if(Directory.Exists(itemImagesFolderPath)) { string[]files=目录.GetFiles(itemImagesFolderPath); 如果(files.Length>0) { chosenImage=文件[0]; } } @类型 @DisplayFor(modelItem=>auction.auction.Title) @DateTimeHelper.LocalDateTime(auction.auction.Starts) @DateTimeHelper.LocalDateTime(auction.auction.Ends) @DisplayFor(modelItem=>auction.auction.IsFeatured) @DisplayFor(modeleItem=>auction.auction.BidCount) @DateTimeHelper.LocalDateTime(auction.auction.AddedDate) @ActionLink(“细节”,“细节”,新的{id=auction.auction.id}) } @PageLinks(Model.pagininfo,x=>Url.Action(Model.Action,new{page=x}))

C# 什么';这个代码怎么了? @使用System.Configuration @使用UI.AuctionService @使用UI.Common @使用UI.Helpers @模型UI.Models.AuctionFrontendListViewModel @{ ViewBag.Title=“拍卖清单”; } @模型名称 形象 类型 拍卖所有权 开始 末端 特色 投标计数 创建时间 @foreach(模型拍卖中的var拍卖) { var type=string.Empty; 如果(拍卖。拍卖是拍卖) { type=“最低唯一赢家”; } else if(auction.auction为电子拍卖) { type=“最高胜利”; } 字符串imagesFolderPath=HttpContextHelper.GetPathInServer(ConfigurationManager.AppSettings[“imagesFolderPath]”); string itemImagesFolderPath=Path.Combine(imagesFolderPath,ImageType.Item+@“\\\”+auction.auction.InventoryReference); string chosenImage=string.Empty; if(Directory.Exists(itemImagesFolderPath)) { string[]files=目录.GetFiles(itemImagesFolderPath); 如果(files.Length>0) { chosenImage=文件[0]; } } @类型 @DisplayFor(modelItem=>auction.auction.Title) @DateTimeHelper.LocalDateTime(auction.auction.Starts) @DateTimeHelper.LocalDateTime(auction.auction.Ends) @DisplayFor(modelItem=>auction.auction.IsFeatured) @DisplayFor(modeleItem=>auction.auction.BidCount) @DateTimeHelper.LocalDateTime(auction.auction.AddedDate) @ActionLink(“细节”,“细节”,新的{id=auction.auction.id}) } @PageLinks(Model.pagininfo,x=>Url.Action(Model.Action,new{page=x})),c#,asp.net-mvc-3,razor,C#,Asp.net Mvc 3,Razor,如果图像是问题所在,我建议您采取不同的做法。您的Razor视图可能不应该负责搜索服务器以查找图像;考虑通过模型或VIEWDATA将信息推到视图中。 另外,为什么要将@“\\”传递到Path.Combine?您正在向路径添加双斜杠。让Path.Combine来处理此问题。我想这可能是你的主要问题。执行以下操作之一: @using System.Configuration @using UI.AuctionService @using UI.Common @using UI.Helpers @mo

如果图像是问题所在,我建议您采取不同的做法。您的Razor视图可能不应该负责搜索服务器以查找图像;考虑通过模型或VIEWDATA将信息推到视图中。

另外,为什么要将
@“\\”
传递到Path.Combine?您正在向路径添加双斜杠。让Path.Combine来处理此问题。我想这可能是你的主要问题。执行以下操作之一:

@using System.Configuration
@using UI.AuctionService
@using UI.Common
@using UI.Helpers

@model UI.Models.AuctionFrontendListViewModel

@{
    ViewBag.Title = "Auction List";
}

<h2>@Model.Title</h2>

<table>
    <tr>
        <th>
            Image
        </th>
        <th>
            Type
        </th>
        <th>
            Auction title
        </th>
        <th>
            Starts
        </th>
        <th>
            Ends
        </th>
        <th>
            Is featured
        </th>
        <th>
            Bid count
        </th>
        <th>
            Creation time
        </th>
        <th></th>   
    </tr>

@foreach (var auction in Model.Auctions)
{
    var type = string.Empty;
    if (auction.Auction is LubAuction)
    {
        type = "Lowest unique wins";
    }
    else if (auction.Auction is EsfAuction)
    {
        type = "Highest wins";
    }

    string imagesFolderPath = HttpContextHelper.GetPathInServer(ConfigurationManager.AppSettings["ImagesFolderPath"]);
    string itemImagesFolderPath = Path.Combine(imagesFolderPath, ImageType.Item + @"\\" + auction.Auction.InventoryReference);
    string chosenImage = string.Empty;
    if (Directory.Exists(itemImagesFolderPath))
    {
        string[] files = Directory.GetFiles(itemImagesFolderPath);
        if (files.Length > 0)
        {
            chosenImage = files[0];
        }
    }

    <tr>
       <td>
            <img src="@chosenImage" />
       </td>
       <td>
            @type
       </td>
       <td>
            @Html.DisplayFor(modelItem => auction.Auction.Title)
        </td>
        <td>
            @DateTimeHelper.LocalDateTime(auction.Auction.Starts)
        </td>
        <td>
            @DateTimeHelper.LocalDateTime(auction.Auction.Ends)
        </td>
        <td>
            @Html.DisplayFor(modelItem => auction.Auction.IsFeatured)
        </td>
        <td>
            @Html.DisplayFor(modelItem => auction.Auction.BidCount)
        </td>
        <td>
            @DateTimeHelper.LocalDateTime(auction.Auction.AddedDate)
        </td>
        <td>
           @Html.ActionLink("Details", "Details", new { id = auction.Auction.Id })
        </td>
    </tr>
}

</table>
<div class="pager">
@Html.PageLinks(Model.PagingInfo, x => Url.Action(Model.Action, new { page = x }))
</div>
或者,更优选地

string itemImagesFolderPath = Path.Combine(imagesFolderPath, ImageType.Item + @"\" + auction.Auction.InventoryReference);

请将您的问题缩小一点-什么特定部分给您带来了问题?您遇到了什么错误?问题是,我无法显示img标记中的图像。您是否查看了渲染输出(“浏览器中的查看源”)要查看html是否按预期呈现?我猜chosenImage字符串从未设置过。显然,在目录中查找映像的代码是错误的。
string itemImagesFolderPath = Path.Combine(imagesFolderPath, ImageType.Item, auction.Auction.InventoryReference);