Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Nullable SelectedID of the DropDownList has always a TRUE ModelState although the ID is Null

$
0
0

My unit tests:

 

[Test]publicvoid DeleteListReleaseViewModel_ReleaseIsNotSelected_ReturnsIsNotValid()
        {new DeleteReleaseListViewModelValidator().ShouldHaveValidationErrorFor(x => x.SelectedId, (int?)null);
        }

        [Test]
        publicvoid DeleteListReleaseViewModel_ReleaseIsSelected_ReturnsIsValid()
        {new DeleteReleaseListViewModelValidator().ShouldNotHaveValidationErrorFor(x => x.SelectedId, new DeleteReleaseListViewModel() { SelectedId = 1 });
        }

Both tests succeed. But when I do manual testing then in the controller the ModelState is true although the SelectedId is NULL.

Why the difference in the behavior?


Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>