doesnt work when i declare it as parameter?

試著忘記壹切 提交于 2019-12-13 18:22:29

问题


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


回答1:


How about this:

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

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



来源:https://stackoverflow.com/questions/2289456/doesnt-work-when-i-declare-it-as-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!