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
Mark TaborPosted Oct 2, 2016, 9:57 AM
Mark TaborPosted Oct 2, 2016, 9:36 AM
Midhun TpPosted Oct 2, 2016, 8:45 AM
Please have a look at below thread-
http://stackoverflow.com/questions/29173165/how-define-the-img-src-path-in-mvc
Mark TaborPosted Oct 2, 2016, 8:16 AM
Delpin Susai Rajthanks for your response
Delpin Susai RajPosted Oct 2, 2016, 7:40 AM
Delpin Susai RajPosted Oct 2, 2016, 7:39 AM