• MVC4 中Remote的使用


    相信当你看到这篇文章的时候对remote是有一些了解了, 起码知道这个东西是来干嘛用的。

    这里也就不废话了 直接上代码  看看Remote的一些使用方式。

    1.判断表单上输入的数据是否存在

        [System.Web.Mvc.Remote("IsPresence", "Goods",ErrorMessage = "申请的物品已存在"]
        [Display(Name = "物品名称")]
        [StringLength(50)]
        /// <summary>
        /// 物品名称
        /// </summary>
        public virtual string Name
        {
          get;
          set;
        }

    2.在实际项目中可能遇到需要结合表单上其他的数据来判断该数据是否存在  则需要用到 AdditionalFields

        [System.Web.Mvc.Remote("IsPresence", "Goods", ErrorMessage = "申请的物品已存在", AdditionalFields = "FKCategory")]
        [Display(Name = "物品名称")]
        [StringLength(50)]
        /// <summary>
        /// 物品名称
        /// </summary>
        public virtual string Name
        {
          get;
          set;
        }

    3.也有可能会遇到需要多个字段同时验证是否存在

        [System.Web.Mvc.Remote("IsPresence", "Goods", ErrorMessage = "申请的物品已存在", AdditionalFields = "FKCategory,ID")]
        [Display(Name = "物品名称")]
        [StringLength(50)]
        /// <summary>
        /// 物品名称
        /// </summary>
        public virtual string Name
        {
          get;
          set;
        }

    4.可能涉及到该表单验证是在MVC的区域中

        [System.Web.Mvc.Remote("IsPresence", "Goods", "GoodsManagement", ErrorMessage = "申请的物品已存在", AdditionalFields = "FKCategory,ID")]
        [Display(Name = "物品名称")]
        [StringLength(50)]
        /// <summary>
        /// 物品名称
        /// </summary>
        public virtual string Name
        {
          get;
          set;
        }

     调用的方法。

        public JsonResult IsPresence(string Name, int FKCategory, int ID = 0)
        {
    
          return Json(bll.IsPresenceName(Name, FKCategory, ID), JsonRequestBehavior.AllowGet);
        }

    以上就是remote的一些简单的应用。 相信这些基本上已经能够实现项目中遇到的问题了。 

  • 相关阅读:
    Unity apk开机自启动一次
    Unity调用Android
    实验 1 Linux 系统的安装和常用命令
    课堂测试3第一阶段数据清洗
    Tutorial_6 运行结果
    Command 'ifconfig' not found, but can be installed with: sudo apt install net-tools VM Ubuntu 解决方案
    《规划极限编程》阅读笔记03
    软件工程_个人课程总结
    《规划极限编程》阅读笔记02
    学习进度_第十六周
  • 原文地址:https://www.cnblogs.com/newer/p/4316054.html
Copyright © 2020-2023  润新知