0

How does binding work? Like how many fields have to match up to make a successful bind. Say you got a Product class with 5 fields and only 4 of the fields match up does it still bind?

Also I know they have an exclude for binding but how do you do multiple excludes? Like if I have 2 fields I want to exclude how do you write that?

1
  • Is this going to be another abandoned question, I wonder?! Commented Aug 21, 2009 at 7:32

2 Answers 2

1

To exclude any number of fields from binding just list them in the action's bind attribute:

public ActionResult Edit([Bind(Exclude = "Id, Username")] int id, FormCollection collection)

At the same time you can explicite define which fields to update:

TryUpdateModel(user.Person, new string[] { "firstname", "lastname", "email", "phone" });
Sign up to request clarification or add additional context in comments.

Comments

0

You could also just type the view

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<Person>" %>

And then

[AcceptVerbs(HttpVerbs.Post)]    
public ActionResult Edit([Bind(Exclude = "Id, Username")]Person person)
{
  // Do the logic.
}

Instead of using TryUpdateModel

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.