为什么BindAttribute应该声明为static

时间:2016-03-02 06:15:31

标签: .net asp.net-mvc entity-framework asp.net-mvc-5

    private string attrNames= "ID,Title,ReleaseDate,Genre,Price";

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit([Bind(Include = attrNames)] Movies movies)
    {
        if (ModelState.IsValid)
        {
            db.Entry(movies).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(movies);
    }

为什么应该将attrNames声明为静态?这是正确的使用方法,只是试验

* .Net MVC 5新手

0 个答案:

没有答案