コード例 #1
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var order = await _context.Orders.FindAsync(id);

            if (order == null)
            {
                return(NotFound());
            }

            var vm = new BladeViewModel(order);
            // setup the items dictionary for the select lists
            // we use the dictionary now because we have two select lists - otherwiwe use SelectItems instead
            var customers   = new SelectList(_context.Customers, "Id", "FullName");
            var orderStatus = _htmlHelper.GetEnumSelectList <OrderStatus>();

            // the keys for the dictionary are specified via the data annotations of the class
            vm.SelectItemsDictionary = new Dictionary <string, IEnumerable <SelectListItem> >()
            {
                { "Customers", customers }, { "OrderStatus", orderStatus }
            };
            // return the view
            return(View("BladeEdit", vm));
        }
コード例 #2
0
        public IActionResult Create()
        {
            var vm = new BladeViewModel(new Customer());

            // set the items for the select list in the view model
            vm.SelectItems = _htmlHelper.GetEnumSelectList <CustomerType>();
            return(View("BladeCreate", vm));
        }
コード例 #3
0
        public IActionResult Create()
        {
            var vm = new BladeViewModel(new Order());
            // setup the items dictionary for the select lists
            // we use the dictionary now because we have two select lists - otherwiwe use SelectItems instead
            var customers   = new SelectList(_context.Customers, "Id", "FullName");
            var orderStatus = _htmlHelper.GetEnumSelectList <OrderStatus>();

            // the keys for the dictionary are specified via the data annotations of the class
            vm.SelectItemsDictionary = new Dictionary <string, IEnumerable <SelectListItem> >()
            {
                { "Customers", customers }, { "OrderStatus", orderStatus }
            };
            // return the view
            return(View("BladeCreate", vm));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var customer = await _context.Customers.FindAsync(id);

            if (customer == null)
            {
                return(NotFound());
            }
            var vm = new BladeViewModel(new Customer());

            // set the items for the select list in the view model
            vm.SelectItems = _htmlHelper.GetEnumSelectList <CustomerType>();
            return(View("BladeEdit", vm));
        }