为什么在asp.net mvc中更改图像链接异步调用控制器

Why changing image link invokes controller asynchronously in asp.net mvc

本文关键字:链接 图像 异步 调用 控制器 asp net mvc 为什么      更新时间:2023-09-26

我正在更改客户端映像的链接,它异步调用控制器。

我不理解这种行为,有人能解释一下发生了什么吗?

为什么url添加实际上默认调用控制器,而且它是异步发生的。

    <script>
        $("#refreshLnk").click(function () {
            $("#cap").attr('src', '@Url.Action("CaptchaImage")?' + new Date().getTime());
        });
    </script>
   <img id="cap" alt="Captcha" src="@Url.Action("CaptchaImage")" style="" />
   <a id="refreshLnk" href="#">refresh</a>
   public ActionResult CaptchaImage()
   {
   }

这是正常和预期的行为。单击按钮时,脚本会将图像的src属性更改为类似"/CaptchaImage?1376967614675"的内容。浏览器尝试渲染图像,从而调用此url。这会触发控制器中的CaptchaImage方法。

有很多帖子与您的问题有关,您可以从以下帖子开始:Url.Action如何工作Asp.netMVC?。希望它能有所帮助!