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

  • 相关阅读:
    Vuex
    浏览器渲染页过程描述
    mvvm 模式
    flex 布局
    js 浮点数计算
    3、异步编程-JS种事件队列的优先级
    高阶函数 debounce 和 throttle
    记录学习MVC过程,HTML铺助类(二)
    记录学习MVC过程,控制器方法和视图(一)
    修改以前项目遇到,所有页面继承BaseBage,Sesssion保存一个model,实现登录(记录一下)
  • 原文地址:https://www.cnblogs.com/newer/p/4316054.html
Copyright © 2011-2022 走看看