RedirectToAction для нескольких действий HttpPost - PullRequest
0 голосов
/ 14 марта 2019

Я создал кнопку, которая направляет на другую страницу с 3 вкладками.

Эти 3 вложенные вкладки имеют различный входной текст и используют только 1 действие [HttpGet].

Это мои дела.

  1. Я хочу сохранить только данные первой вкладки, значение 2 вкладок будет нулевым
  2. Я хочу сохранить только вторые данные, 1-я вкладка и 3-я вкладка будут нулевыми
  3. Я хочу сохранить весь введенный текст на 1-й вкладке, 2-й вкладке и 3-й вкладке.

Вот мой код:

 [HttpGet]
 public ActionResult Create_Data(int productId)
 {
      var model = BigViewModel();
      ///rest of code
      return View(model)
 }

 [HttpPost]
 public ActionResult Create_Data(BigViewModel model, int productId)
 {
      int experimentForOverloading = 0;
      string experimentAgain = ""

      // validates if first tab and doesn't have data inputted, will redirect to Create_SecondTab. Below is just for testing
      if (model.FirstTabName == null && model.ThirdTabDirectory == null)
      {

           // this is where I want to go to route the new Action. But I don't know what to do..
           return RedirectToAction("CreateData", new
           {
                model = BigViewModel,
                Id = productId,
                experimentForOverloading
           }
      }
      else if (model.SecondTabSalary == null && model.ThirdTabDirectory == null)
      {
           return RedirectToAction("CreateData", new
           {
                model = BigViewModel,
                Id = productid
                experimentAgain
           }
      }
      else
      {
           return RandomView(); //Testing purposes
      }
 }

 // This is the second case, save only when first tab is empty
 [HttpPost]
 public ActionResult CreateData(BigViewModel, int bigId, int experimentForOverloading)
 {
      if(ModelState.IsValid)
      {
           //.. code here
           _context.SaveChanges()
      }
      else
      {
           return RandomView(); //Testing purpose
      }
 }

 // This is the first case, save only when second and third tab is empty
 [HttpPost]
 public ActionResult CreateData(BigViewModel, int bigId, string experimentAgain)
 {
      if(ModelState.IsValid)
      {
           //.. code here
           _context.SaveChanges()
      }
      else
      {
           return RandomView(); //Testing purpose
      }
 }
...