vendredi 16 octobre 2020

How to get values of selected items id in CheckBox in ASP.NET CORE?

I have 3 table. first one for Movie , second one for Category, third one(MovieCategor) its hold MovieId and Category Id

I want to insert Movie and choose the category. I list to category like checkbox to page View. How to make intsert for Movie and MovieCategor table ?

View Page @foreach (var category in Model.Categories) {

                <div class="form-check">
                    <input  type="checkbox" value="@category.Id" name="" class="form-check-input" id="exampleCheck1">
                    <label class="form-check-label" for="exampleCheck1">@category.CategoryName</label>
                </div>
            }

controller

public IActionResult Create(MovieCreateViewModel movieCreateViewModel)
    {
        if (ModelState.IsValid)
        {
           

            string fileName = UploadFile(movieCreateViewModel);
            Movie movie = new Movie()
            {
                Name = movieCreateViewModel.Name,
                Director = movieCreateViewModel.Director,
                Summary = movieCreateViewModel.Summary,
                Banner = fileName
            };
            _movieService.Add(movie);
            return RedirectToAction("List");
        }

        return View();
    }



Aucun commentaire:

Enregistrer un commentaire