Hi From the calling Action Method, I have:
[HttpPost]
public JsonResult SubmitForms(Note note, string action = "Submit")
{
//some code
RedirectToAction("SaveDemographicForm", "PatientForms", new { model.DemographicFormData, action="Submit" , submitAll = true });
//some code
}
And this the Action Method that I am trying to call:
[HttpPost]
public JsonResult SaveDemographicForm(DemographicForm demographicForm, string action = "Save", bool submitAll = false )
{
//Some code
}
What am I doing wrong here? Thanks in advance.
While ASP.NET MVC will allow you to have two actions with the same name, . NET won't allow you to have two methods with the same signature - i.e. the same name and parameters. You will need to name the methods differently use the ActionName attribute to tell ASP.NET MVC that they're actually the same action.
you want to call same function of controller. In this case there is no need to add action before function name. this is simple you can call function of same controller using $this->functionName().
I'm assuming you want to return that action's result. var ctrl= new MyController(); ctrl. ControllerContext = ControllerContext; //call action return ctrl. Action();
If they are both in the same controller you don't need to redirect to action, just call it directly.
[HttpPost]
public JsonResult SubmitForms(Note note, string action = "Submit")
{
//some code
return SaveDemographicForm(new DemographicForm { /*your properties*/ }, "Save", false);
}
[HttpPost]
public JsonResult SaveDemographicForm(DemographicForm demographicForm, string action = "Save", bool submitAll = false )
{
//return some json object
}
Just call with no return
[HttpPost]
public JsonResult SubmitForms(Note note, string action = "Submit")
{
SaveDemographicForm(new DemographicForm { /*your properties*/ }, "Save", false);
//somecode
//submitforms return
}
[HttpPost]
public JsonResult SaveDemographicForm(DemographicForm demographicForm, string action = "Save", bool submitAll = false )
{
//return some json object
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With