小编rem*_*mco的帖子

未调用 HttpPost 方法

当我运行我的代码时,我的 HttpGet 方法似乎工作正常。但是当我尝试将值返回给我的 HttpPost 操作时,它只会运行我的 HttpGet 方法,然后我收到“NullReferenceException”错误。

这是我的代码。

我在控制器中的操作:

[HttpGet]
        public IActionResult AddMovie(int? id)
        {
            List<Movie> movieList = new List<Movie>();
            movieList = dbContext.Movies.ToList();

            AddMovieViewModel viewModel = new AddMovieViewModel()
            {
                movies = movieList,
                customer = dbContext.Customers.Where(s => s.CustomerId == id).FirstOrDefault()
            };

            return View(viewModel);
        }

        [HttpPost]
        public IActionResult AddMovie (int id,int cid)
        {
            Customer customer = dbContext.Customers.Where(s => s.CustomerId == cid).FirstOrDefault();
            Movie movie = dbContext.Movies.Where(s => s.MovieId == id).FirstOrDefault();
            customer.BorrowingMovies.Add(movie);
            customer.BorrowingMovies.Add(movie);
            return View();
        }
Run Code Online (Sandbox Code Playgroud)

在这里我的观点

@model MovieExampleAppDotNetCore.ViewModels.AddMovieViewModel
@{
    ViewData["Title"] = "AddMovie";
    Layout …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc

2
推荐指数
1
解决办法
314
查看次数

标签 统计

asp.net-core-mvc ×1

c# ×1