in my view
Inherits="System.Web.Mvc.ViewUSerControl<Model.Person>"
How can I use an interface to restrict what the view is capable of accessing from the model? is this safe?
in my view
Inherits="System.Web.Mvc.ViewUSerControl<Model.Person>"
How can I use an interface to restrict what the view is capable of accessing from the model? is this safe?
Let Person class has several properties and you want only Name property be accessible from a view. Declare interface like this and use it:
public interface RestrictedPerson
{
string Name
{
get;
set;
}
}
public partial class Person: RestrictedPerson
{
}
in a view's Page directive set
Inherits="System.Web.Mvc.ViewPage<Model.RestrictedPerson>
and pass to view Person object as usual.