在视图中使用 java 脚本调用 MVC 操作
我有一个包含图像的视图,我想设置一个按钮来通过调用我的控制器中的操作来重新加载该图像,如下所示:
<a href="javascript://" class="Button ButtonLarge" id="Reload"><span><span class="ButtonIcon NewTopic">Refresh</span></span></a>
以及如下操作:
public ActionResult Image()
{
var builder = new XCaptcha.ImageBuilder();
var result = builder.Create();
Session.Add("SecurityNumber", result.Solution);
return new FileContentResult(result.Image, result.ContentType);
}
我需要使用 javascript 调用此操作并设置新的图像源任何帮助会好的
I have a view that contain a image i want to set a button to reload this image by calling an action in my controller like this :
<a href="javascript://" class="Button ButtonLarge" id="Reload"><span><span class="ButtonIcon NewTopic">Refresh</span></span></a>
and the action like this:
public ActionResult Image()
{
var builder = new XCaptcha.ImageBuilder();
var result = builder.Create();
Session.Add("SecurityNumber", result.Solution);
return new FileContentResult(result.Image, result.ContentType);
}
i need to call this action using javascript and set the new image source any help will be good
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要更新图像,只需更新 src 属性即可。使用 jQuery:
它的作用是,当您单击 id 为“Reload”的元素时,将 id 为“Captcha”的图像的“src”属性设置为“/path/of/your/action”。
e.preventDefault()
就在那里,所以我们不点击该链接。To update an image, just update the src attribute. Using jQuery:
What this does is when you click an element with id "Reload", set the "src" attribute of the image with id "Captcha" to "/path/of/your/action".
e.preventDefault()
is there so we do not follow the link.