Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想使用MVC表单进行验证_Javascript_Jquery_Asp.net Mvc_Forms_Validation - Fatal编程技术网

Javascript 我想使用MVC表单进行验证

Javascript 我想使用MVC表单进行验证,javascript,jquery,asp.net-mvc,forms,validation,Javascript,Jquery,Asp.net Mvc,Forms,Validation,我有一个html表单,当我更改单选按钮时有输入。这些单选按钮具有空案例的验证。例如,我检查了invoiceTypePerson和 填写其输入,然后单击提交按钮,但由于其他radiobutton的输入为空,表单未提交。我想让他们彼此独立。 我怎么做?下面是我的代码 <div class="inputs"> @Html.RadioButtonFor(model => model.InvoiceType, InvoiceType.Person, new { id = "inv

我有一个html表单,当我更改单选按钮时有输入。这些单选按钮具有空案例的验证。例如,我检查了invoiceTypePerson和 填写其输入,然后单击提交按钮,但由于其他radiobutton的输入为空,表单未提交。我想让他们彼此独立。 我怎么做?下面是我的代码

<div class="inputs">
    @Html.RadioButtonFor(model => model.InvoiceType, InvoiceType.Person, new { id = "invoiceTypePerson" })
    <label for="invoiceTypePerson" class="companyType">@T("RadioButton1")</label>
    @Html.RadioButtonFor(model => model.InvoiceType, InvoiceType.Company, new { id = "invoiceTypeCompany" })
    <label for="invoiceTypeCompany" class="companyType">@T("RadioButton2")</label>
</div>

<div class="inputs sirket">
    @Html.TextBoxFor(model => model.TaxOffice, new { @class = "text-box single-line", required = "required" })
    @Html.RequiredHint()
    <span class="taxD"></span>
</div>

<div class="inputs sahis">
    @Html.TextBoxFor(model => model.TcNumber, new { @class = "text-box single-line", required = "required" })
    @Html.RequiredHint()
    <span class="tc"></span>
</div>

<button class="add-address-button"></button>

if($("input[id='invoiceTypePerson']").is(":checked")){
    $('.add-address-button').click(function(){
            var tc = $('input[id*="Address_TcNumber"]').attr('value');
            if (!tc) {
                $("span.tc").html('TC is required');
                return false;
            }
            else if(tc){
                $("span.tc").html('');
            }

            var taxoffice = $('input[id*="Address_TaxOffice"]').attr('value');
            if (!taxoffice) {
                $("span.taxD").html('Taxoffice is required');
                return false;
            }
            else if(tc){
                $("span.taxD").html('');
            }           
    });
}

@RadioButton(model=>model.InvoiceType,InvoiceType.Person,新的{id=“invoiceTypePerson”})
@T(“RadioButton1”)
@RadioButton(model=>model.InvoiceType,InvoiceType.Company,新的{id=“invoiceTypeCompany”})
@T(“RadioButton2”)
@TextBoxFor(model=>model.TaxOffice,新的{@class=“text box single line”,required=“required”})
@Html.RequiredHint()
@Html.TextBoxFor(model=>model.TcNumber,新的{@class=“text box single line”,required=“required”})
@Html.RequiredHint()
如果($(“输入[id='invoiceTypePerson']”)是(“:选中”)){
$('.add address按钮')。单击(函数(){
var tc=$('input[id*='Address_TcNumber']).attr('value');
如果(!tc){
$(“span.tc”).html('tc是必需的');
返回false;
}
否则如果(tc){
$(“span.tc”).html(“”);
}
var taxoffice=$('input[id*=“Address_taxoffice”]).attr('value');
如果(!税务局){
$(“span.taxD”).html(“需要税务局”);
返回false;
}
否则如果(tc){
$(“span.taxD”).html(“”);
}           
});
}

现在构建表单时,用户可以选择个人和公司。如果单选按钮值是互斥的,那么它们应该具有相同的名称,以便用户可以选择个人或公司,但不能同时选择两者。你的问题不清楚,你能稍微改写一下吗?我不明白你的表格在哪里?这句话是什么时候找到的?:
如果($($input[id='invoiceTypePerson'])是(“:checked”){
(它是在文档上准备好的还是在哪里?请更具体一些。