views:

284

answers:

1

Hi,
If i declare the Bind attribute as a parameter on the method, it doesnt work as it expected

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude="ID")]int ServiceId, Event evnt)
        {
            var service = dbSrc.GetAll().WithID(ServiceId).SingleOrDefault();
            if (service == null)

But if i declare it on the class level, it works!

[Bind(Exclude = "ID")]
    partial class Event
    {

The form firing the create action is in the usercontrol and i am using asp.net mvc 1 ?

My db setup is fine. The id column is primary key and auto generated.

What might be the reason ? or it s a bug in the version 1.0 ?

Thanks in advance

+5  A: 

How about this:

public ActionResult Create(int ServiceId, [Bind(Exclude="ID")]Event evnt)

instead? I'm betting ServiceId has no ID property.

Craig Stuntz
Thanks Craig, it works! But what is the reason ? Is it because the custom parameters come first and then the model with Bind attirubute follows it ?
Barbaros Alp
When you put `[Bind` *inside* the `()` on a method, you are putting the attribute on an *individual argument*, not on the whole method.
Craig Stuntz
I understand now, thank you so much.
Barbaros Alp