tags:

views:

60

answers:

1

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?

+3  A: 

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.

Alexander Prokofyev
is there any way anyone (hacker) could still get to the original object by doing this?
zsharp
If he doesn't have access to the hosted application and can't modify source code you shouldn't worry. This can't be hacked from the client side.
Alexander Prokofyev
i did this and field from original person were visible in the debugger as pasrt of the Model.
zsharp