The model item passed into the dictionary is null, but this dictionary requires a non-null model ite

Posted by Sheonarayan under Error and Solution on 7/11/2014 | Points: 10 | Views : 1430 | Status : [Administrator] | Replies : 2

Problem

This error generally occurs when we have a function or parameter expecting non nullable value but we are passing null value.

Solution

To solve this error, we can write code snippet like this
@model Nullable<bool>
@{
bool active = false;
if (Model != null)
{
active = (bool)Model.HasValue;
}
}

where bool has been converted into nullable dictionary and we are checking for Model = null and if it is not then converting it boolean. In further code we can use active variable if needed.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com



Responses

Posted by: Vuyiswamb on: 7/12/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
hi Sheo please change the Category to "Errors and Solutions"

Thanks

Thank you for posting at Dotnetfunda
[Administrator]

Sheonarayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 7/13/2014 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Done, Thanks Vuyiswamb.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sheonarayan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response