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
-
you can use jquery $.get . api.jquery.com/jQuery.get instead of using javascriptJayantha Lal Sirisena– Jayantha Lal Sirisena2011年08月29日 09:20:46 +00:00Commented Aug 29, 2011 at 9:20
-
I need it to be using javascriptEslam Soliman– Eslam Soliman2011年08月29日 09:22:46 +00:00Commented Aug 29, 2011 at 9:22
-
or if you can give me an exampl of how can i do it in jquereyEslam Soliman– Eslam Soliman2011年08月29日 09:24:10 +00:00Commented Aug 29, 2011 at 9:24
-
yes I am not verey good with itEslam Soliman– Eslam Soliman2011年08月29日 09:27:14 +00:00Commented Aug 29, 2011 at 9:27
1 Answer 1
To update an image, just update the src attribute. Using jQuery:
$("#Reload").click(function(e) {
$("#Captcha").attr("src", "/path/to/your/action");
e.preventDefault();
});
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.
-
<script type="text/javascript"> $(document).ready(function () { $("#Reload").click(function (e) { $("#image").attr("src", "/AccountController/Image"); e.preventDefault(); }); )}; </script>
Eslam Soliman– Eslam Soliman2011年08月29日 09:31:45 +00:00Commented Aug 29, 2011 at 9:31 -
@Eslam Yes, that should work. Are you sure you want the Controller suffix in there? I guess it should be "/Account/Image".alexn– alexn2011年08月29日 09:32:30 +00:00Commented Aug 29, 2011 at 9:32
-
thanks a lot alexn ,and i have a nother question can i made it without reloading the pageEslam Soliman– Eslam Soliman2011年08月29日 09:37:21 +00:00Commented Aug 29, 2011 at 9:37
-
it reloads the image only one time is there is something in what i wroteEslam Soliman– Eslam Soliman2011年08月29日 09:49:06 +00:00Commented Aug 29, 2011 at 9:49
Explore related questions
See similar questions with these tags.