MVC中使用ajax设置必填

Model:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace WebApplicationAccount.Models
{
    public class Account
    {
        /// <summary>
        /// 客户id
        /// </summary>
        public Guid id { get; set; }//客户id
        /// <summary>
        /// 客户名称
        /// </summary>
        [Required]
        public string new_name { get; set; }//客户名称
        /// <summary>
        /// 销售修改者
        /// </summary>
        public string modifiedby { get; set; }//销售修改者
        /// <summary>
        /// 客户类型
        /// </summary>
        public string new_cust_type { get; set; }//客户类型
        /// <summary>
        /// 身份证号
        /// </summary>
        [StringLength(18, MinimumLength = 18)]
        [Required]
        public string new_id_no { get; set; }//身份证号
        /// <summary>
        /// 生日
        /// </summary>
        public string new_birthday { get; set; }//生日
        /// <summary>
        /// 年龄
        /// </summary>
        public string new_age { get; set; }//年龄
        /// <summary>
        /// 手机号码
        /// </summary>
        [StringLength(11,MinimumLength = 11)]
        [Required]
        public string new_mobile { get; set; }//手机号码
        /// <summary>
        /// 教育背景
        /// </summary>
        public string new_education { get; set; }//教育背景
        /// <summary>
        /// 职业
        /// </summary>
        public string new_occupation { get; set; }//职业
        /// <summary>
        /// 行业
        /// </summary>
        public string new_industrycode { get; set; }//行业
        /// <summary>
        /// 手机号码2
        /// </summary>
        public string new_mobile2 { get; set; }//手机号码2
        /// <summary>
        /// 微信号
        /// </summary>
        public string new_wechart { get; set; }//微信号
        /// <summary>
        /// 邮件
        /// </summary>
        public string new_email { get; set; }//邮件
        /// <summary>
        /// 详细地址
        /// </summary>
        public string new_address { get; set; }//详细地址
        /// <summary>
        /// 省
        /// </summary>
        public string new_province1 { get; set; }//省
        /// <summary>
        /// 市
        /// </summary>
        public string new_city { get; set; }//市
        /// <summary>
        /// 年收入(万元)
        /// </summary>
        public decimal new_annual_income { get; set; }//年收入(万元)
        /// <summary>
        /// 月可支配收入(元)
        /// </summary>
        public decimal new_monthly_disposable { get; set; }//月可支配收入(元)
        /// <summary>
        /// 现金流水情况(元)
        /// </summary>
        public decimal new_cash_flow { get; set; }// 现金流水情况(元)
        /// <summary>
        /// 性别
        /// </summary>
        public string new_gender1 { get; set; }//性别
        /// <summary>
        /// 婚姻状况
        /// </summary>
        public string new_marital_status { get; set; }//婚姻状况
        /// <summary>
        /// 利率偏好
        /// </summary>
        public string new_interest_rate { get; set; }//利率偏好
        /// <summary>
        /// 金融产品偏好
        /// </summary>
        public string new_financial_product_preference { get; set; }//金融产品偏好
        /// <summary>
        /// 期数偏好
        /// </summary>
        public string new_installments_preferences { get; set; }//期数偏好
        /// <summary>
        /// 客户标签
        /// </summary>
        public string new_cust { get; set; }//客户标签
        /// <summary>
        /// 个人信用情况
        /// </summary>
        public string new_credit_status { get; set; }//个人信用情况
    }
}

Controller:

 public ActionResult CreateAccount(Account account)
{
    if (account.new_mobile == null)
            {
                return Content("手机号码");
            }
}

 View:

<script>
function CreateAccount() {
        $.ajax({
            url: "/Home/CreateAccount",
            type: "post",
            data: {
                "new_mobile": $("#new_mobile").val()
            },
            success: function (data) {
                /*alert(111111)//有弹框*/
                    if (data == "手机号码") {
                        alert("手机号码不能为空");
                    } 
                }

            }
        });
    }
</script>
<div>
    <input type="submit" value="添加" onclick="CreateAccount()" />
</div>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值