2

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?

2 Answers 2

3

Use the BindAttribute with the Exclude tag

public ActionResult Create( [Bind(Exclude="ID, CreatedOn")]Comment comment )
{
}
Sign up to request clarification or add additional context in comments.

2 Comments

Awesome Tvanfosson :) I'm also assuming that an Include property is valid, for whitelisting?
Opps. soz. Tvanfosson - i missed your MSDN link. The members page (msdn.microsoft.com/en-us/library/…) lists the 4 properties. sweet. Include is one and of course Prefix which is also very handy. cheers mate!
-2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.