gpt4 book ai didi

javascript - 使用knockoutjs在MVC中绑定(bind)图像路径

转载 作者:行者123 更新时间:2023-11-28 15:24:14 26 4
gpt4 key购买 nike

我想使用 knockoutjs 在我的 MVC 应用程序中显示图像。我正在使用以下代码。 JavaScript(image.js)

 function viewModel() {
this.ImgPath = ko.observable("~/Content/Images/abcd.JPG");
};
ko.applyBindings(new viewModel());

在 View 中,

<img data-bind="attr: { src: ImgPath }" />

我还在我的 View 中添加了以下内容。

<script src="~/Scripts/jquery-2.1.3.js"></script>
<script src="~/Scripts/knockout-3.3.0.js"></script>
<script src="~/Scripts/images.js"></script>

但是图像没有在我的应用程序中显示。如何使用knockout绑定(bind)图像路径到mvc中查看?

最佳答案

将图像路径从 "~/Content/Images/abcd.JPG" 更改为 "/Content/Images/abcd.JPG"

HTML 无法理解

~ 并且不会加载图像。 ~ 只能被 ASP.Net 引擎理解。

关于javascript - 使用knockoutjs在MVC中绑定(bind)图像路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29839425/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com