TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mark Tabor
589
2k
460.1k
MVC Partial views changes the reference of css,Images and js
Oct 2 2016 7:02 AM
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<slider> 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<slider> files = new List<slider>();
var model = new System.Collections.Generic.List<slider>();
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
Reply
Answers (
6
)
Forget password
Auto Complete text box not working in Master's content page