ASP.NET MVC - Alternative for [Bind(Exclude = “Id”)]

前端 未结 5 2169
执笔经年
执笔经年 2020-12-05 00:42

Is there an alternative for [Bind(Exclude = \"Id\")] (Related Question) ?

Could I write a model binder?

5条回答
  •  天命终不由人
    2020-12-05 01:17

    A very simple solution that I figured out.

    public ActionResult Edit(Person person)
    {
        ModelState.Remove("Id"); // This will remove the key 
    
        if (ModelState.IsValid)
           {
               //Save Changes;
           }
        }
    }
    

提交回复
热议问题