When my DateReturned
is null, I want to add a link in my html that redirects me to ~/CohortSubscriptions/Edit
which allows me to add a DateReturned
@{
var dateReturned = Model.DateReturned == null ? "" : Url.Content(Model.DateReturned);
}
When I do this my 2nd Model.DateReturned
issues the following error:
"can not convert from 'System.DateTime?' to 'String' "
What is the right way to write it?
Url.Content
expects a string
, not a DateTime
object.
You can fix it by:
Url.Content(Model.DateReturned.ToString()); //you might want to specify a format.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.