Doesn't work when I declare it as a parameter?

If I declare the Bind attribute as a method parameter, it does not work as 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 at the class level, it works!

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

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

My db setup is great. The id column is the primary key and is automatically generated.

What could be the reason? or is this a bug in version 1.0?

Thank you in advance

+1
source share
1 answer

How about this:

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

instead of this? I am sure it ServiceIdhas no property ID.

+6
source

Source: https://habr.com/ru/post/1709277/


All Articles