Nullable Decimal If Is Always True

빨간

작업 주문 내의 항목을 나열하는 페이지가 있습니다. 이러한 각 항목에는 많은 속성과 할인 속성이 있습니다. 작업 주문에 할인이없는 경우 열을 숨기고 싶은 경우 값이있는 라인에 대해 표시해야합니다.

값은 데이터베이스에서 가져오고 Discount는 nullable 10 진수로 가져 오는 nullable 10 진수 열입니다.

컨트롤러에서 할인이 있는지 확인하고 ViewBag에 NoDiscount라는 부울을 설정합니다.

ViewBag.NoDiscount == 거짓 검사는 영광이지만, 그것이 사실이고 경우 item.Discount.HasValue 검사 테스트, 항상 true를 반환합니다.

@if (ViewBag.NoDiscount == false) {
    <div class="col-xs-2" style="border-top: solid 1px #DDD;">
        if (@item.Discount.HasValue) {
        @item.Discount.Value.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture(ViewBag.Currency))
        }
    </div>
}

코드를 깨고 null 항목에 대해 Discount.HasValue가 있는지 테스트하면 false를 반환하지만 코드는 계속됩니다.

내가 얻는 오류는 다음과 같습니다.

An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code

Additional information: Nullable object must have a value.
빨간

내가 묻기 전에 한 시간 동안보고, 묻고 5 분 후에 직접 해결합니다.

내 @의 위치가 잘못되었습니다.

@if (ViewBag.NoDiscount == false) {
<div class="col-xs-2" style="border-top: solid 1px #DDD;">
    @if (item.Discount.HasValue) {
    @item.Discount.Value.ToString("C", System.Globalization.CultureInfo.CreateSpecificCulture(ViewBag.Currency))
    }
</div>
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Cast string to decimal? (nullable decimal) by extension method

분류에서Dev

DisplayFor in razor with nullable decimal changes format

분류에서Dev

Why is this PHP if condition always true?

분류에서Dev

AHK if statment with variables not working always true

분류에서Dev

Logical in my R function always returns "TRUE"

분류에서Dev

if(!buydat.empty()) validation fails (always true)

분류에서Dev

PropertyInfo.GetValue on Boolean is always True

분류에서Dev

Function always returning true no matter input

분류에서Dev

Why does my condition always evaluate as true?

분류에서Dev

Map function applied on tuple always inexplicably evaluates to True

분류에서Dev

Is T(n) >= T(n-1) always true?

분류에서Dev

Does the double-exclamation (!!) trick always produce true or false in JavaScript?

분류에서Dev

assertText in Selenium IDE: always true, due to target being display:none

분류에서Dev

Comparing two string iterators always comes out true C++

분류에서Dev

Why the hash command in bash always returns true for ./<something>

분류에서Dev

Linq Lambda 함수를 사용하여 Nullable Decimal을 백분율로 합산

분류에서Dev

public Nullable <bool>을 통해 Entity에서 Sql로 비트 1에 대한 bool true 값

분류에서Dev

'=='연산자를 'System, .Nullabe <decimal>'및 'System.Nullable <double>'유형에 적용 할 수 없습니다. 오류

분류에서Dev

Why is this Angular expression in an ng-class inside an ng-repeat always treated as true?

분류에서Dev

장고 | NULL = True로 설정하더라도 Decimal Field는 필수입니다.

분류에서Dev

Swashbuckle 5.x를 사용하여 일반 T 매개 변수 참조 속성에서 nullable = true 지정

분류에서Dev

'System.Collections.Generic.List`1 유형의 개체를 캐스팅 할 수 없습니다. [<> f__AnonymousType6`65 [System.String, System.Decimal, System.Nullable`1

분류에서Dev

의미 : void * _Nullable (* _Nonnull) (void * _Nullable)

분류에서Dev

Kotlin에서 nullable의 nullable?

분류에서Dev

JSON의 경우 스키마 추론이 Spark로 남아있을 때 Spark가 nullable = true를 출력하는 이유는 무엇입니까?

분류에서Dev

Filtering List with nullable values

분류에서Dev

nullable 작업

분류에서Dev

@Column(nullable=false) Not Working

분류에서Dev

Programmatically set column nullable

Related 관련 기사

  1. 1

    Cast string to decimal? (nullable decimal) by extension method

  2. 2

    DisplayFor in razor with nullable decimal changes format

  3. 3

    Why is this PHP if condition always true?

  4. 4

    AHK if statment with variables not working always true

  5. 5

    Logical in my R function always returns "TRUE"

  6. 6

    if(!buydat.empty()) validation fails (always true)

  7. 7

    PropertyInfo.GetValue on Boolean is always True

  8. 8

    Function always returning true no matter input

  9. 9

    Why does my condition always evaluate as true?

  10. 10

    Map function applied on tuple always inexplicably evaluates to True

  11. 11

    Is T(n) >= T(n-1) always true?

  12. 12

    Does the double-exclamation (!!) trick always produce true or false in JavaScript?

  13. 13

    assertText in Selenium IDE: always true, due to target being display:none

  14. 14

    Comparing two string iterators always comes out true C++

  15. 15

    Why the hash command in bash always returns true for ./<something>

  16. 16

    Linq Lambda 함수를 사용하여 Nullable Decimal을 백분율로 합산

  17. 17

    public Nullable <bool>을 통해 Entity에서 Sql로 비트 1에 대한 bool true 값

  18. 18

    '=='연산자를 'System, .Nullabe <decimal>'및 'System.Nullable <double>'유형에 적용 할 수 없습니다. 오류

  19. 19

    Why is this Angular expression in an ng-class inside an ng-repeat always treated as true?

  20. 20

    장고 | NULL = True로 설정하더라도 Decimal Field는 필수입니다.

  21. 21

    Swashbuckle 5.x를 사용하여 일반 T 매개 변수 참조 속성에서 nullable = true 지정

  22. 22

    'System.Collections.Generic.List`1 유형의 개체를 캐스팅 할 수 없습니다. [<> f__AnonymousType6`65 [System.String, System.Decimal, System.Nullable`1

  23. 23

    의미 : void * _Nullable (* _Nonnull) (void * _Nullable)

  24. 24

    Kotlin에서 nullable의 nullable?

  25. 25

    JSON의 경우 스키마 추론이 Spark로 남아있을 때 Spark가 nullable = true를 출력하는 이유는 무엇입니까?

  26. 26

    Filtering List with nullable values

  27. 27

    nullable 작업

  28. 28

    @Column(nullable=false) Not Working

  29. 29

    Programmatically set column nullable

뜨겁다태그

보관