How does the ASP.NET MVC UpdateModel() method work?

后端 未结 3 1154
时光取名叫无心
时光取名叫无心 2020-12-28 14:01

I\'m working on my first .NET MVC application and using the NerdDinner tutorial as a reference point. One point that is intriguing me at the moment is the UpdateModel(

3条回答
  •  滥情空心
    2020-12-28 14:16

    Instead of passing Model object as a parameter to "Post()" action method, we are creating an instance of an Model object within the "Post()" function, and updating it using "UpdateModel()" function. "UpdateModel()" function inspects all the HttpRequest inputs such as posted Form data, QueryString, Cookies and Server variables and populate the employee object.

    e.g.

    [HttpPost]
    [ActionName("Create")]
    public ActionResult Create_Post()
    {
            EmployeeBusinessLayer employeeBusinessLayer =
                new EmployeeBusinessLayer();
            Employee employee = new Employee();
            UpdateModel(employee);
            employeeBusinessLayer.AddEmmployee(employee);
            return RedirectToAction("Index");
    }
    

提交回复
热议问题