以前一直对C#的GDI画图部分知识点不怎么用所以忘得差不多了,这两天正好公司要做一个博客系统,其中一个需求就是留言时为了防止恶意攻击必须填写验证码,正好借着这个机会复习了一下,以下是实现代码,写的比较简单。

View 层

 1 @{
 2     ViewBag.Title = "Home Page";
 3 } 
 4 <div class="row">
 5      <h1>test</h1>
 6     <div class="col-lg-12">
 7         @using(Html.BeginForm("Index","Home", FormMethod.Post, new {@ }))
 8         {
 9             <div class="form-group">
10                 <input type="file" name="file"/>
11                 <input type="file" name="files" />
12                 <button>提交</button>
13             </div>
14             <div class="form-group">
15                 <div class="col-lg-1">
16                     <input type="text" class="col-lg-3"/>
17                 </div>
18                 <div class="col-lg-3">
19                     <img id="img" onclick="CheckCode()" src="/Home/GetValidateCode" style="height:30px;width:110px" title="点击更换" alt="点击更换" />
20                     <a href="javascript:void(0)" onclick="CheckCode()">点击更换</a>
21                 </div>
22             </div>
23         }
24     </div>
25 </div>
26 @section scripts{
27 <script>
28     $(function () { 
29         $("#img").click(function () {
30             CheckCode()
31         })
32     })
33     function CheckCode() {
34         $("#img").attr("src", "/Home/GetValidateCode?date="+new Date());
35     }
36      
37 </script>
38 }
View Code

相关文章:

猜你喜欢
  • 2021-12-07
  • 2021-12-31
  • 2021-12-31
  • 2021-06-12
  • 2022-03-10
相关资源
相似解决方案