asp.net mvc - How to get value from interface? -
i have :
public class usercontactinformation : iusercontactinformation { public bool isdefaultcontactinformation { get; set; } public string email { get; set; } }
and interface:
public interface iusercontactinformation { bool isdefaultcontactinformation { get; set; } string email { get; set; } string phone { get; set; } }
how can email in controller because don't see usercontactinformation
in controller. it's not visible. need function getemail()
? can`t use this:
model.email = user.usercontactinformation.email;
your code invalid won't compile because can't have phone
defined in interface , fail implement in class has defined.
public interface iusercontactinformation { bool isdefaultcontactinformation { get; set; } string email { get; set; } string phone { get; set; } } // invalid public class usercontactinformation : iusercontactinformation { public bool isdefaultcontactinformation { get; set; } public string email { get; set; } } // valid public class usercontactinformation : iusercontactinformation { public bool isdefaultcontactinformation { get; set; } public string email { get; set; } // if in interface, needs implemented public string phone { get; set; } }
secondly, if want print email
, presumably within view, set model in view , print
using razor syntax:
exampleview.cshtml:
@model iusercontactinformation <p>hello, email address @model.email<p>
Comments
Post a Comment