【问题标题】:how to implement click binding on image in mvc如何在mvc中实现对图像的点击绑定
【发布时间】:2016-05-20 14:27:15
【问题描述】:

这是我想在点击图片时传递 id 的简单图片:

<img class="pull-right" src="~/assest/image/cross.png" data-bind="attr: { href: unfollowAction }" alt="" />

但它没有击中控制器操作方法。我在这里实现 knockout.js 以将 id 发送到取消关注操作方法,如下所示:

self.unfollowAction = location.protocol + "//" + location.host + '/Post/Unfollow?uid=' + data.PostId;

请提前告诉我 img tag helper.many many thnks 中 data-bind 的正确语法。

【问题讨论】:

    标签: jquery asp.net-mvc knockout.js


    【解决方案1】:

    嗯,你应该试试这样的:

       <a data-bind="attr:{ href: unfollowAction }">
          <img class="pull-right" src="~/assest/images/cross.png" alt="" />
        </a>
    

    【讨论】:

      【解决方案2】:

      你需要一个 Html 动作图片

      @Html.ActionImage("unfollowAction", new { id = MyId }, "~/Content/Images/Image.bmp", "Edit")
      

      查看answer了解更多详情

      【讨论】:

      • 如何在此处添加 data-bind 属性??
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      • 2013-11-16
      • 2021-11-20
      • 2012-02-24
      • 1970-01-01
      相关资源
      最近更新 更多