c# - Make MVC not post back one of the members in the model which is an interface -
i have view model looks this:
class myviewmodel { public string stuff { get; set; } public ifoo foo { get; set; } }
the requests work fine because supply both, stuff
, ifoo
view.
however, when posting back, mvc says can't make object of interface.
now, have 2 options:
a) change type of foo
property concrete implementation, no big deal; or
b) model binding myself, overkill want. don't care posting ifoo
member.
how tell mvc not post ifoo? don't have html controls representing ifoo
. properties ifoo
, use hidden thingies in view.
you can exclude properties binding.
via model
[bind(exclude="foo")] class myviewmodel { public string stuff { get; set; } public ifoo foo { get; set; } }
via action
[httppost] public actionresult mygreataction([bind(exclude="foo")]myviewmodel model) { }
Comments
Post a Comment