7

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.

NASSER
  • 5,900
  • 7
  • 38
  • 57
user2948533
  • 1,143
  • 3
  • 13
  • 32

4 Answers4

11

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
}
Stephen Brickner
  • 2,584
  • 1
  • 11
  • 19
1

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
}
Nurkartiko
  • 183
  • 2
  • 10
1

The RedirectToAction() returns a RedirectToRouteResult:

public ActionResult AnotherAction(int id)
{
    //Do something with the id ...
    return View()
}


public RedirectToRouteResult DoAndRedirect()
{            
    //Do something and go to the desired view:
    return RedirectToAction("AnotherAction", new { id = x.ID });
}
Exel Gamboa
  • 936
  • 1
  • 14
  • 25
1
  • using System.Web.Mvc;
  • using System.Web.Mvc.Html;

    public ActionResult Index()
    {
        HtmlHelper helper = new HtmlHelper(new ViewContext(ControllerContext, new WebFormView(ControllerContext, "Index"), new ViewDataDictionary(), new TempDataDictionary(), new System.IO.StringWriter()), new ViewPage());
        helper.RenderAction("Index2");//call your action
    
        return View();
    }
    
    public ActionResult Index2(/*your arg*/)
    {
        //your code
        return new EmptyResult();
    }
    
Hossein Hajizadeh
  • 1,357
  • 19
  • 10