zoukankan      html  css  js  c++  java
  • 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的一些简单的应用。 相信这些基本上已经能够实现项目中遇到的问题了。 

  • 相关阅读:
    MYSQL5.7.11安装问题
    Controllerizing the ScrollViewer Thumbnail
    WPF Tutorial
    How to properly release Excel COM objects
    How to detect and avoid memory and resources leaks in .NET applications
    [Forward]Ten Caching Mistakes that Break your App
    Process.StandardOutput
    .NET Framework posters with Namespaces & Types
    【转】常用 Microsoft .NET Framework 各版本下載網址列表
    6 ways to import data into SQL Server
  • 原文地址:https://www.cnblogs.com/newer/p/4316054.html
Copyright © 2011-2022 走看看