문제

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