views:

132

answers:

2

Hi folks, I've got a standard ASP.NET MVC form post.

eg.

<% using (Html.BeginForm<CommentController>(c => c.Create())) { %>    
..
<% } %>

(and in the controller)

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Comment comment)
{ .. }

Now, how can i make it so that i IGNORE certain values, like the ID or CreatedOn properties, that might exist in the Comment object?

Is there a way i can define an exclusion/black list?

A: 

Whatever inputs you have within your form HTML will be passed in with the submission by default.

Sorry I don't have an answer off the top of my head, but I'd start by looking into some possible jQuery plugins and/or some AJAX filtering mechanisms.

Boydski
+2  A: 

Use the BindAttribute with the Exclude tag

public ActionResult Create( [Bind(Exclude="ID, CreatedOn")]Comment comment )
{
}
tvanfosson
Awesome Tvanfosson :) I'm also assuming that an Include property is valid, for whitelisting?
Pure.Krome
Opps. soz. Tvanfosson - i missed your MSDN link. The members page (http://msdn.microsoft.com/en-us/library/system.web.mvc.bindattribute_members.aspx) lists the 4 properties. sweet. Include is one and of course Prefix which is also very handy. cheers mate!
Pure.Krome