我试图用 js 和 ASP.NET MVC3 razor 更新验证码。我找到了这个解决方案:查看:
<div id ="CaptchaDiv"> <img alt="Captcha" id="Captchaimg" src="@Url.Action("GetCaptcha")" style="" /></div> <input type="button" value="Refresh" onclick=" return GetCaptcha()" />
控制器:
public ActionResult GetCaptcha ()
{
FileContentResult img = null;
int res = 0;
MemoryStream mem = Metods.CaptchaImage( out res);
Session["Captcha"] = res;
img = this.File(mem.GetBuffer(), "image/Jpeg");
return img;
}
JS:
function GetCaptcha()
{
$('Captchaimg').attr('src', '/Account/GetCaptcha?' + new Date().getTime());
}
但是:它不起作用。JS 运行成功。但控制器动作不运行。怎么了?有任何想法吗?