質問

In this function

    [HttpGet]
    public ActionResult Create_Summary(Guid? appointmentId)
    {
        if (appointmentId.HasValue)
        {
            var appointment = _appointmentRepository.GetAppointmentDetails(appointmentId);
            var summary = new CreateAppointmentSummary
            {
                NameOrSubject = appointment.Subject,
                Location = appointment.Location,
                DescriptionOrRemarks = appointment.Description
            };
            return View(summary);
        }
        else
        {
            var summary = new CreateAppointmentSummary();
            return View(summary);
        }

    }

I get error : Cannot convert System.Guid? to System.Guid while calling the repository function.

What I want to do make this action to be able to be called with some null guid value as well from some other view. But if they call with some not null guid value then call the resposiotry function to do some search.

But i'm having trouble to make this work.

役に立ちましたか?

解決

What Brandon said - you need this when you call the repository function.

var appointment = _appointmentRepository.GetAppointmentDetails(appointmentId.Value);

Guid? and Guid are totally different types; GetAppointmentDetails requires Guid.

他のヒント

Please try :

(Guid?) new Guid(appointmentId)

just cast it: (Guid?)(new Guid(myString))

there is also an implicit cast, so this would work fine as well: Guid? g = new Guid(myString);

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top