this is my code:
public IActionResult Details(int id)
{
List<SugestionViewModel> sugest = new List<SugestionViewModel>();
SugestionViewModel s = new SugestionViewModel();
var shoes = _db.Shoes.Find(id);
List<string> picname = new List<string>();
string[] FilePath = Directory.GetFiles(Path.Combine(_env.WebRootPath, "Images\Shoes\" + shoes.Code_Fani));
foreach (string file in FilePath)
{
picname.Add(shoes.Code_Fani + "/" + Path.GetFileName(file));
}
ViewBag.Image = picname.ToList();
var VideoPath = Path.Combine("wwwroot\Media\IGTV\" + shoes.Video);
if (System.IO.File.Exists(VideoPath))
{
string[] FilePath2 = Directory.GetFiles(Path.Combine(_env.WebRootPath, "Media\IGTV\" + shoes.Code_Fani));
ViewBag.media = shoes.Code_Fani + "/" + Path.GetFileName(FilePath2[0]);
}
var sugestion = _db.Sugestions.ToList();
foreach (var su in sugestion)
{
Shoes shose1 = _db.Shoes.Where(t => t.Group_Id == su.Group_id).Last();
string[] FilePath1 = Directory.GetFiles(Path.Combine(_env.WebRootPath, "Images\Shoes\" + shose1.Code_Fani));
s.Name = "کفش مدل" + shose1.Code_Fani;
s.Image = shoes.Code_Fani + "/" + Path.GetFileName(FilePath1[0]);
sugest.Add(s);
}
ViewBag.sugestion = sugest.ToList();
if (shoes != null)
{
return View(shoes);
}
else return NotFound();
}
I want to show an object by id which I get it from another view but my action run twice so in second time becuase id is zero I have error.why my action have to run twice ?