Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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# foreach循环在_PartialView页中工作时未显示图像_C#_Asp.net Mvc_Razor - Fatal编程技术网

C# foreach循环在_PartialView页中工作时未显示图像

C# foreach循环在_PartialView页中工作时未显示图像,c#,asp.net-mvc,razor,C#,Asp.net Mvc,Razor,我有一个像下面这样的模型课 public class UserViewModel { public UserViewModel() { UsersDet = new Dictionary<long, string>(); usrdat = new List<User>(); } public Dictionary<long , string> UsersDet { get; set

我有一个像下面这样的模型课

public class UserViewModel
{
    public UserViewModel() 
    {
        UsersDet = new Dictionary<long, string>(); 
        usrdat  = new List<User>();    
    }

    public Dictionary<long , string> UsersDet { get; set; }
    public IEnumerable<User> usrdata { get; set; }
}
这是将值绑定到上述弹出窗口的控制器方法

    [HttpGet]
    public PartialViewResult MethodName(int id)
    {
        try
        {    

            IEnumerable<User> listofData = ..
            UserViewModel listofimage = new UserViewModel();


            if (listofData != null) 
            {
                listofimage.usrdata = listofData;

                foreach(var item in listofimage.usrdata)
                {
                    var path = RenderImage(item.ImageValue, "UploadImagePath");                        

                    var fileResult = path as FilePathResult;

                    if (fileResult != null)
                    {

                        string imageurl = fileResult.FileName;

                        imageurl = imageurl.Replace(@"\\", @"\");

                        listofimage.UsersDet.Add(item.CaseID, imageurl);
                    }                        
                }
            }                

            return PartialView("_UserView", listofimages);   

        }
        catch (Exception)
        {
            throw;
        }

    } 

    public ActionResult RenderImage(string imageid, string pathvalue)
    {
        try
        {
            var URL = System.Configuration.ConfigurationManager.AppSettings[pathvalue].ToString();
            var path = Path.Combine(URL, imageid + ".jpg");
            return base.File(path, "image/jpeg");
        }
        catch (Exception)
        {
            throw;
        }
    }
[HttpGet]
公共PartialViewResult方法名(int id)
{
尝试
{    
IEnumerable listofData=。。
UserViewModel listofimage=新的UserViewModel();
if(listofData!=null)
{
listofimage.usrdata=listofidata;
foreach(listofimage.usrdata中的变量项)
{
var path=RenderImage(item.ImageValue,“UploadImagePath”);
var fileResult=路径作为FilePathResult;
if(fileResult!=null)
{
字符串imageurl=fileResult.FileName;
imageurl=imageurl.Replace(@“\\”,@“\”);
添加(item.CaseID,imageurl);
}                        
}
}                
返回PartialView(“用户视图”,图像列表);
}
捕获(例外)
{
投掷;
}
} 
公共操作结果呈现(字符串imageid、字符串pathvalue)
{
尝试
{
var URL=System.Configuration.ConfigurationManager.AppSettings[pathvalue].ToString();
var path=path.Combine(URL,imageid+“.jpg”);
返回base.File(路径“image/jpeg”);
}
捕获(例外)
{
投掷;
}
}

我的
foreach
方法中有什么错误如何将元素填充为循环

如果Model.UsersDet中填充了项,那么将呈现
  • 元素。如果它们已渲染,但您看不到图像,则打开devtools并在“网络”选项卡中查找对每个图像的请求。如果有请求有错误响应,那么您可以根据返回的http状态修复它


    但是没有要调试的项目,如果您说@for正在工作,但@foreach没有,那么问题应该是Model.UsersDet是空的

    UsersDet
    中是否有任何项目(您在哪里填充)?是的,可能有多个项目include@kez
    Model.UsersDet
    不包含任何项,调试代码或至少显示foreach循环前的项数
    @Model.UsersDet.Count
    @AhmedRagheb问题更新,实际上,当我调试时,我可以看到,
    @foreach(Model.UsersDet中的var item)
    无法生成任何html的唯一方法是,如果集合中没有项(并且仍然使用我看到的上一个问题中的无意义:):),这是一个很好的可能性,但我正在从partialview调试,我可以看到Model.UsersDet计数also@kez与web中的所有内容一样,所有内容都与请求及其响应有关:)
    @model Project.ViewModels.UserViewModel
    
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body" style="width: 530px;">
                <div id="slider_view" style="display: block;">
                    <div class="flexslider">
                        <ul class="slides">
                            @for (int i =0; i < 3 ; i ++)
                            {         
                                <li data-thumb="~/Upload_Images/A.jpg">
                                    <img src="~/Upload_Images/A.jpg" data-imagedata="image001" />
                                    <p class="flex-caption">Title</p>
                                </li>
                            }
                        </ul>
                    </div>
                </div>
           </div>
        </div>
    </div>
    
        [HttpGet]
        public PartialViewResult MethodName(int id)
        {
            try
            {    
    
                IEnumerable<User> listofData = ..
                UserViewModel listofimage = new UserViewModel();
    
    
                if (listofData != null) 
                {
                    listofimage.usrdata = listofData;
    
                    foreach(var item in listofimage.usrdata)
                    {
                        var path = RenderImage(item.ImageValue, "UploadImagePath");                        
    
                        var fileResult = path as FilePathResult;
    
                        if (fileResult != null)
                        {
    
                            string imageurl = fileResult.FileName;
    
                            imageurl = imageurl.Replace(@"\\", @"\");
    
                            listofimage.UsersDet.Add(item.CaseID, imageurl);
                        }                        
                    }
                }                
    
                return PartialView("_UserView", listofimages);   
    
            }
            catch (Exception)
            {
                throw;
            }
    
        } 
    
        public ActionResult RenderImage(string imageid, string pathvalue)
        {
            try
            {
                var URL = System.Configuration.ConfigurationManager.AppSettings[pathvalue].ToString();
                var path = Path.Combine(URL, imageid + ".jpg");
                return base.File(path, "image/jpeg");
            }
            catch (Exception)
            {
                throw;
            }
        }