これは私のビューの一部です:
<img src="@{Html.RenderAction("GetUserProfileImage", "Home", new { area = "" });}" alt="" />
そして私のコントローラー:
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);
}
}
したがって、DBからファイルを取得する場合はすべて問題ありませんが、URL(by return Content
)を返すと、レンダリングされたhtmlに次のような悪い結果が生じます。
<imghttp: myproject.dev="" content="" img="" sample_user.png="" src="" alt="">
<div>
some content from outside of img tag added here
</div>
</imghttp:>
また、ビューを次のように変更します。
<img src="http://myproject.dev/Content/img/sample_user.png" alt="" />
そして、すべてがOKです、
では、どこに問題があるのでしょうか。コンテンツは単純な文字列を属性に返すことができないようです。では、単純src
な文字列を返すための提案は何ですか?
それが不可能な場合
DBから返されるときにURL(http://myproject.dev/Content/img/sample_user.png
)などでファイルを取得すると思いreturn File()
ますが、このURl()でコントローラーにファイルを取得するにはどうすればよいhttp://myproject.dev/Content/img/sample_user.png
ですか?
そしてあなたが持っているなら他の提案はありますか?