ASP MVC: Upload Image from Database as Full Background CSS

旧时模样 提交于 2020-05-16 04:10:35

问题


I'm still fiddling with MVC and I want to set a full background image which would be retrieved from the database.

This is what I used to do in CSS and love to do whenever I need full background:

.banana3-sm{
    background-image: url('../images/banana3-sm.png');
    background-size: contain;
    background-position: center center;
    background-repeat: no-repeat;
    height: 100%;
}

Below is what I'm using currently because I don't know how to upload the image link from database to CSS.

In Controller:

model.ImgSrc = Convert.ToBase64String(model.Image);

In CSHTML:

<div class="col-lg-6 col-md-6 visible-md visible-lg">
    @Html.Partial("_ProductImage", Model)
</div>

In PartialView

<img class="img-responsive" src="@imgSrc" alt="Product Image" /> 

But the image isn't as responsive as I want it to be in the above <img> way.

So there a way I could insert the image link into here dynamically?

background-image: url('xx/xx/xxxx.png'); 

Thanks in advance!

And I have already read these similar threads as well on here:

how-to-apply-full-background-image-in-asp-net-mvc

css-background-image-refuses-to-display-in-asp-net-mvc

来源:https://stackoverflow.com/questions/47009912/asp-mvc-upload-image-from-database-as-full-background-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!