I have a website in mvc and in _Layout.cshtml i have a slider my code of slider is shown below i am getting the images from a folder
public class slider : Controller
{
public string src { get; set; }
public string title { get; set; }
public List GetData()
{
string[] filePaths = Directory.GetFiles(System.Web.HttpContext.Current.Server.MapPath("/Images/img/"));
//string[] filePaths = Directory.GetFiles(Url.Content(System.Web.HttpContext.Current.Request.MapPath("/Images/img/")));
List files = new List();
var model = new System.Collections.Generic.List();
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
model.Add(new slider
{
title = fileName.Split('.')[0].ToString(),
src = "../Images/img/" + fileName
});
}
return model;
}
}
Now this slider works fine for Home Controller Index View , It also works fine for Service Controller Index view , but when i click on any of the service to show its details in a new partial view then my images get broken , when i inspect the element i found that instead of finding the image from the Root/Images/Go.png it is finding from Root/Service/Images/go.png where service is my controller method , Why it is so check the above code as well where i am using server.Mappath 
Delpin Susai RajRank #53 · 29.5K reputationPosted Oct 2, 2016, 3:39 AM EDT
Delpin Susai RajRank #53 · 29.5K reputationPosted Oct 2, 2016, 3:40 AM EDT
Mark TaborRank #914 · 2.3K reputationPosted Oct 2, 2016, 4:16 AM EDT
Delpin Susai Rajthanks for your response
Midhun TpRank #388 · 6.5K reputationPosted Oct 2, 2016, 4:45 AM EDT
Please have a look at below thread-
http://stackoverflow.com/questions/29173165/how-define-the-img-src-path-in-mvc
Mark TaborRank #914 · 2.3K reputationPosted Oct 2, 2016, 5:36 AM EDT
$('#image').attr('src', '/Images/send.jpg'); $('#image').attr('src', '@Url.Content("~/Images/send.png")');Mark TaborRank #914 · 2.3K reputationPosted Oct 2, 2016, 5:57 AM EDT