This is my part of View:
<img src="@{Html.RenderAction("GetUserProfileImage", "Home", new { area = "" });}" alt="" />
And My Controller:
public ActionResult GetUserProfileImage() {
string defaultresult = "http://MyProject.dev/Content/img/sample_user.png";
if (Member.LogIn()) {
DBFile file = GetMemberPicFromDB();
return File(file.Content, file.ContentType);
} else {
return Content(defaultresult);
}
}
So when I Get File from DB every thing is OK, but when I return URL(by return Content) there is some bad result in rendered html, something like this:
<imghttp: myproject.dev="" content="" img="" sample_user.png="" src="" alt="">
<div>
some content from outside of img tag added here
</div>
</imghttp:>
Also I change the View to:
<img src="http://myproject.dev/Content/img/sample_user.png" alt="" />
And every thing is OK,
So where is the problem? it seems return Content can not return simple string to src attribute, So what is your suggestion for return simple string?
if that not possible
I think to get File by URL(http://myproject.dev/Content/img/sample_user.png) and return File() Like when returned from DB, but how can I get the file in controller by this URl(http://myproject.dev/Content/img/sample_user.png) ?
and any other suggestion if you have?
You should return a file from your controller action in both cases and reference this action in your image, like this:
and then in your controller action return a File result in both cases: