Esempio n. 1
0
        public async Task <IActionResult> AddBook([FromBody] AddNewDynamicItem parameters)
        {
            // This is the POST action that will be called whenever the user clicks
            // the "Add new item" link in a DynamicList view. It accepts a an object
            // of the class ListItemParameters that contains information about where
            // the item needs to be inserted (i.e. the id of the div to where contents
            // as well as the path to your viewmodels in the main form). All of those
            // are computed automatically from the view by the library.

            var newBookViewModel = new BookViewModel()
            {
                Title           = "New book",
                PublicationYear = "1994"
            };

            // Now you have to call the extension PartialView method passing the view model
            // and any additional options you might want to include in your view model. This
            // is an extension method that creates a partial view with the needed HTML prefix
            // for the fields in your form so the form will post correctly when submitted.

            // Note: when using POST, we need to pass as well an instance of ICompositeViewEngine
            // which you can obtain through Dependency Injection in your controller's constructor.
            return(await this.PartialViewAsync(_viewEngine, newBookViewModel, parameters, new MyOptions <BookViewModel>()
            {
                Title = "Item title",
                Subtitle = "Note: the close button should have different styles in the Create and in the Edit " +
                           "views. This happens because the Create.cshtml view passes an extra parameter to the template " +
                           "to set it to red.",
                CanRemove = true
            }));
        }
Esempio n. 2
0
        public IActionResult AddBook(AddNewDynamicItem parameters)
        {
            // This is the GET action that will be called whenever the user clicks
            // the "Add new item" link in a DynamicList view. It accepts a an object
            // of the class ListItemParameters that contains information about where
            // the item needs to be inserted (i.e. the id of the div to where contents
            // as well as the path to your viewmodels in the main form). All of those
            // are computed automatically from the view by the library.

            // Now here you can create another view model for your model
            var newBookViewModel = new BookViewModel()
            {
                Title           = "New book",
                PublicationYear = "1994"
            };

            // Now you have to call the extension PartialView method passing the view model
            // and any additional options you might want to include in your view model. This
            // is an extension method that creates a partial view with the needed HTML prefix
            // for the fields in your form so the form will post correctly when submitted.
            return(this.PartialView(newBookViewModel, parameters, new MyOptions <BookViewModel>()
            {
                Title = "Dynamic item",
                Subtitle = "Note: This text was set in the AuthorsController even though the view models " +
                           "did not include a field for it. The 'options' mechanism used by this library avoids " +
                           "cluttering your existing view models with too many little details about the view.",
                CanRemove = true
            }));
        }
Esempio n. 3
0
        public IActionResult AddReagent(AddNewDynamicItem parameters)
        {
            var reagentChoices  = _context.Reagents.Select(r => new { r.Id, r.Name }).ToList();
            var newOrderReagent = new OrderReagent()
            {
                ReagentChoices = new SelectList(reagentChoices, "Id", "Name")
            };

            return(this.PartialView(newOrderReagent, parameters));
        }
        public IActionResult AddMaterial(AddNewDynamicItem parameters)
        {
            // This is the GET action that will be called whenever the user clicks
            // the "Add new item" link in a DynamicList view. It accepts a an object
            // of the class ListItemParameters that contains information about where
            // the item needs to be inserted (i.e. the id of the div to where contents
            // as well as the path to your viewmodels in the main form). All of those
            // are computed automatically from the view by the library.

            // Now here you can create another view model for your model
            var newMaterialViewModel = new MaterialViewModel()
            {
                Title = "New Material"
            };

            // Now you have to call the extension PartialView method passing the view model.
            // This is an extension method that creates a partial view with the needed HTML
            // prefix for the fields in your form so the form will post correctly when it
            // gets submitted.
            return(this.PartialView(newMaterialViewModel, parameters));
        }