小编Rau*_*bid的帖子

如何根据复选框值验证文本框

我试图根据复选框值验证文本框.请查看我的模型类和IsValid覆盖方法.

public class Product
{
    //Below property value(HaveExperiance)
    [MustBeProductEntered(HaveExperiance)] 
    public string ProductName { get; set; }

    public bool HaveExperiance { get; set; }
}

public class MustBeTrueAttribute : ValidationAttribute
{
    //Here i need the value of HaveExperiance property which 
    //i passed from  [MustBeProductEntered(HaveExperiance)]  in product class above.
    public override bool IsValid(object value)
    {
        return value is bool && (bool)value;
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以ProductNameproduct类中的属性中看到iam尝试传递HaveExperiance类属性值,如果已检查,则用户必须填写ProductName文本框.

所以我的原始问题是如何ProductName根据HaveExperiance价值验证文本框,提前感谢.

编辑:

using System;
using System.Collections.Generic; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-4

3
推荐指数
1
解决办法
578
查看次数

如何将List从视图传递到控制器 - MVC 4

从视图到控制器传递列表时我错过了一个小东西.它在控制器的[HttpPost]方法中显示null.任何人请指导我如何从视图到控制器获取列表数据.请查看下面的完整代码.

@model List<payorder_draft_printing.Models.registration>

@{
    ViewBag.Title = "bulk_approval";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="container">

    <div class="row" style="text-align: left">

        <h2><u>Bulk Approval</u></h2>

        <br />
        <br />

        @using (Html.BeginForm("bulk_approval", "Sms", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <div style="width: 700px;" align="center">

                <table id="GetSerial" class="table">
                    <thead>
                        <tr class="ui-widget-header">
                            <th>Account Number</th>
                            <th>Mobile Number</th>
                            <th>Customer Name</th>
                            <th>Branch Code</th>
                            <th>Bulk Upload</th>
                            <th>Create Date</th>
                            <th>Created By</th>
                            <th>Active</th>
                           </tr>
                    </thead>

                    <tbody>

                        @if (Model != null)
                        {
                            foreach (var m in Model)
                            {
                            <tr style="height: 25px; border-bottom: 1px solid gray"> …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-4

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-mvc-4 ×2

asp.net-mvc ×1

c# ×1