Esempio n. 1
0
        [ActionName("Edit")]       //重名处理
        public ActionResult EditCategory()
        {
            var category = new NewsCategory();
            //使用白名单更新实体,防止表单绑定分配漏洞
            var categoryWhite = new[] { "ParentID", "Name", "DisplayName", "Order", "Describe" };
            var isValid       = TryUpdateModel(category, categoryWhite);

            if (isValid)
            {
                _service.AddNewsCategory(category);
                return(RedirectToAction("List"));
            }
            else
            {
                var categoryView = new NewsCategoryView();
                isValid = TryUpdateModel(categoryView, categoryWhite);
                return(View(categoryView));//返回带错误信息的模型
            }
        }