相关疑难解决方法(0)

如何将条件必需属性放入类属性以使用WEB API?

我只想放置与WEB API一起使用的条件必需属性

public sealed class EmployeeModel
{
      [Required]
      public int CategoryId{ get; set; }
      public string Email{ get; set; } // If CategoryId == 1 then it is required
}
Run Code Online (Sandbox Code Playgroud)

我通过(ActionFilterAttribute)使用模型状态验证

c# custom-attributes asp.net-mvc-4 asp.net-web-api

20
推荐指数
2
解决办法
2万
查看次数

MVC.NET Core 中的条件验证(RequiredIf)

我正在尝试有条件地验证 MVC.NET Core 中的字段。我有两个单选按钮。如果我选择是(对于所有权),我想在下面设置一个字段(活动下拉菜单)

但是,无论我多么努力,要验证的值总是来自 Activity 字段,而不是来自 Ownership 字段(“N\A”而不是“Yes”)

有人可以告诉我我做错了什么吗

视图 (chtml)

<div class=" form-group">
    <div class="bisformdynamiclabel"></div>
    <br />
    @Html.RadioButtonFor(model => model.BIS232Request.JSONData.OwnershipActivity.Ownership, "Yes", new { id = "OwnershipAnswer_true", onclick = "displayOwnershipFieldsRow(true)" })
    <label for="OwnershipAnswer_true">Yes</label>
    @Html.RadioButtonFor(model => model.BIS232Request.JSONData.OwnershipActivity.Ownership, "No", new { id = "OwnershipAnswer_false", onclick = "displayOwnershipFieldsRow(false)" })
    <label for="OwnershipAnswer_false">No</label>
    <span class="alert-danger">
        @Html.ValidationMessage("OwnershipAnswer")
    </span>
</div>
<div class="row ownershipfieldsrow">
    <div class="col-xs-12 col-md-12">
        <div class=" form-group">
            <div class="bisformdynamiclabel"></div>
            <br />
            <input style="display:none" class="form-control" type="text" asp-for="BIS232Request.JSONData.OwnershipActivity.Activity" />
            <select class="form-control ownershipactivityselect" onchange="$('#BIS232Request_JSONData_OwnershipActivity_Activity').val($(this).val());  ">
                <option value="N/A">Please …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc

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