Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Int null checker on a partial view

I have a partial view which does not have any parameters passed to it and is called by multiple apps.

I however want to change the requirements and pass a nullable int to it and a null checker, but it fails, I am a bit confused, how do I go about this ?

My confusion lies with this line >> Id ?? null ? user.UserId() ;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

heres my code

[HttpGet]
public PartialViewResult GetUserById (int ? Id)
{
     var user = new GetAuthenticatedUser() ;  /// This is a custom inhouse code that returns the User ID and properties

    Id ?? null ? user.UserId() ;  // I am trying to test if the Id is null then use the user account, if not user the query string Id value
     var userId = _user.GetUserBasedOnId(Id)
 
}

// In a nutshell what I am trying to achieve is this

if (Id == null )
{
         var userId = _user.GetUserBasedOnId(user.UserId)
}
else
{
         var userId = _user.GetUserBasedOnId(Id)
}

If I tried

Id = Id ?? null ? user.UserId() ;

I get the error

CS0019 Operator ?? cannot be applied to operants of type int and

>Solution :

Declare the int as nullable by changing

public PartialViewResult GetUserById (int ? Id)

to

public PartialViewResult GetUserById (int? Id)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading