zoukankan      html  css  js  c++  java
  • MVC添加分布视图做唯一验证

    Model里的代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace MvcApplication5.Models
    {
        public class zhuceBF
        {
            private MyDBDataContext _context = new MyDBDataContext();
            //定义一个Bool类型的查询方法
            public bool Select(string id)
            {
                var query = _context.zhuce.Where(P=>P.ID==id);
                return query.Count() > 0;
            }
        }
    }


    这是控制器里的代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using MvcApplication5.Models;
    namespace MvcApplication5.Controllers
    {
        public class HomeController : Controller
        {
            //
            // GET: /Home/
    
            public ActionResult Index()
            {
                return View();
            }
    
            //这里查询后返回一个部分视图
            public ActionResult Check(string id)
            {
                bool isok = new zhuceBF().Select(id);
                return PartialView(isok);
            
            }
    
        }
    }


    这是主视图代码

    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        <div>
            @Html.TextBox("ID") <input id="Button1" type="button" value="唯一验证" onclick="yanzheng()"  />
            <div id="ss"></div>  @* 部分视图在这个div显示*@
        </div>
    </body>
    </html>
    <script src="~/jquery-1.11.2.min.js"></script>
    <script type="text/javascript">
    
        //当点击唯一验证的时候,触发这个函数,并指向Home控制器里的Check动作,在Check动作里会返回一个部分视图,
        //视图就会在Id名是ss的div里
        function yanzheng() {
            var a = $("#ID").val();
            $("#ss").load("/Home/Check/" + a);
        }
        </script>

    部分视图代码

    @model bool
    @if(Model)
    {
        <div>无效</div>
    }
    else
    {
         <div>可以使用</div>
    }
  • 相关阅读:
    codeforces #586 ABC~D
    codeforces #585 div2 ABCD
    编译原理实验 NFA子集法构造DFA,DFA的识别 c++11实现
    codeforces #599 div2 ABCD
    codeforces #598 div3 ABCDF
    codeforces #587 div3 ABCDE
    codeforces educational round 73 div2 ABCD
    Mud Puddles ( bfs )
    2019牛客多校第十场B.Coffee Chicken(递归)
    2019牛客多校训练第七场A. String(暴力)
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4645141.html
Copyright © 2011-2022 走看看