I want to display an image immediately after fill the textbox, don't need to click any button for get the picture.
I did this in my view:
@using (Html.BeginForm())
{
<input value="" id="UserID" name="UserID" type="text" class="form-control" />
<img id="CaptchaImg" alt="Captcha" src="@Url.Action("showFoto", "loan")" style="" />
}
<script language="javascript" type="text/javascript">
$.ajax({
type: "POST",
url: '@Url.Action("showFoto", "loan")',
datatype: "image/jpg",
success: function (UserID) {
$('#CaptchaImg').attr('src', UserID);
}
});
</script>
In my controller Loan.cs:
[HttpPost]
public string showFoto(string UserID)
{
string ImageID = UserID;
var virtualPath = string.Format("~/images/profile/{0}.jpg", ImageID);
if (System.IO.File.Exists(Server.MapPath(virtualPath)))
{
return virtualPath;
}
return null;
}
My information was from:get a image through jquery ajax Please, need your helps... thanks!