我创建了一个按钮,该按钮可以转到带有3个标签的另一页。
这3个子选项卡具有不同的输入文本,并且仅使用1个Action [HttpGet]。
这些是我的情况。
这是我的代码:
[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
}
}