我继续得到错误:“值不能为空”即使我正在检查空值。 这是我的代码的一部分:
<script type="text/javascript">
if (typeof @Model.Project.ProjectPricings.Count() != 'undefined' &&
@Model.Project.ProjectPricings.Count())
{
numberOfPricings = @Model.Project.ProjectPricings.Count();
}
sourceCodeList = '@Html.Raw(string.Join("", Model.SourceCodeList.Select(x => "<option></option><option value=" + x.SourceCode + ">" + x.SourceCode + "</option>")))';
targetCodeList = '@Html.Raw(string.Join("", Model.TargetCodeList.Select(x => "<option value="+ x.TargetCode + ">" + x.TargetCode + "</option>")))';
unitTypeCodeList = '@Html.Raw(string.Join("", Model.UnitTypeCodeList.Select(x => "<option value="+ x.UnitTypeCode + ">" + x.UnitTypeCode + "</option>")))';
currencyList = '@Html.Raw(string.Join("", Model.CurrencyList.Select(x => "<option value="+ x.CurrencyCode + ">" + x.CurrencyCode + "</option>")))';
serviceCodeList = '@Html.Raw(string.Join("", Model.ServiceCodeList.Select(x => "<option value="+ x.ServiceCode + ">" + x.ServiceCode + "</option>")))';
frequencyList = '@Html.Raw(string.Join("", Model.VolumeFrequencyList.Select(x => "<option value="+ x.VolumeFrequencyDescription + ">" + x.VolumeFrequencyDescription + "</option>")))';
@*$(document)
.ready(function() {
if (@Model.Project.Id == null) {
addPricing();
}
});*@
$('#submit-price-button').button();
$(".date").datepicker();
$(".combobox").SumoSelect({ search: true, searchText: 'Enter here.' });
</script>
答案 0 :(得分:0)
根据您的说明和评论,我的理解是您在检查@Model.Project.ProjectPricings.Count()
有价值的地方时遇到了问题,是否设置了值。
你的问题是你正在混合剃须刀和javascript代码进行验证 - 在你的情况下,直接检查服务器端(因此剃须刀)似乎是合乎逻辑的
所以请将您的代码更改为:
@if (Model.Project.ProjectPricings != null)
{
@:numberOfPricings = @Model.Project.ProjectPricings.Count();
}
// rest same