0

Well, I have 2 actions in different controller but the work procedure is almost same however their input parameter are slightly different. One action is receiving some POST parameter in addition with model where as other action does not. So I would like to call one action from another controller through the different action. Therefore I need to pass the POST parameters as well. So what do I do?

For example My Main Action is like in ProcedureController controller

public virtual byte[] GenerateProcedureReports(Report model)
{
      procedureListIds = Request.Form["ProcedureMultiCheckList"].Trim();
}

Look here I am receiving procedureListIds from Form request So if I redirect any route to this action how do I send this parameter ProcedureMultiCheckList

I have tried this way by studying this Questions 1, 2, 3. However I didn't get any solution regarding to this problem.

I have tried by this way from ProcedureJobsController

        public virtual ActionResult JobReport(long id)
        {
            var jobInformation = _procedureJobService.Get(id);
            if (jobInformation.IsFromTablet)
            {
                Report report = new Report();
                return RedirectToAction("GenerateProcedureReports", "Procedures", new {report =report,  ProcedureMultiCheckList = jobInformation.ProcedureId });
            }
}

Here I have tried to pass model and the POST parameter(ProcedureMultiCheckList), but it is not receiving as a Form request parameter. So, how do I solve this problem? If this can be done I will be able to reduce thousands line of code. Pretty pathetic, Huh?

Community
  • 1
  • 1
Ananda G
  • 2,389
  • 23
  • 39
  • Couple of clarification before I post an answer: `Report model` where is it coming from - also POST of form? Also, is there a particular requirement of issuing a redirect rather than fulfilling the request? – LB2 May 22 '17 at 18:29
  • Question 1. Yes, Report model is coming from a POST of a form. Question 2. Yes. I have a different requirement therefore I can't combine the actions. I need to fulfill some other extra work the I am redirecting the action. – Ananda G May 23 '17 at 04:07
  • Can you clarify Q2 for me - what is that requirement that cannot be handled inline on the request. Usually it is something like returning partial data to client so client can submit additional info, but I don't see it here, hence why I'm trying to understand it. – LB2 May 23 '17 at 15:39

2 Answers2

0

I think it should be something like this:

public virtual ActionResult JobReport(long id)
{
    var jobInformation = _procedureJobService.Get(id);
    if (jobInformation.IsFromTablet)
    {
        Report report = new Report();
        TempData["ProcedureMultiCheckList"] = jobInformation.ProcedureId;
         return RedirectToAction("GenerateProcedureReports", "Procedures", new {report = report });
    }
}

reading TempData:

var procedureMultiCheckList = TempData["ProcedureMultiCheckList"]
Scrobi
  • 1,215
  • 10
  • 13
  • I don't have any property in `Report` model which named `ProcedureMultiCheckList` If anything is taken from request then there is no need to keep it in the model. – Ananda G May 22 '17 at 07:39
  • In that case you cannot pass as a parameter. You can either update the model to persist the data in another way .e.g. TempData, see updated example. – Scrobi May 22 '17 at 07:41
  • Your procedure seems that it is possible, but I have to change something from my controller. But I will do that if `var procedureMultiCheckList = TempData["ProcedureMultiCheckList"]` for `POST` method seperately. – Ananda G May 22 '17 at 08:42
0
public class HomeController: Controller
{
  public ActionResult MyAction(MyModel model)
  {
    return RedirectToAction("MySimilarAction", "About", new{model=model, age=40, name="my Name"});
  }
}


public class AboutController: Controller
{
  public ActionResult MySimilarAction(MyModel model, int age, string name)
  {

  }
}
Bhuban Shrestha
  • 1,304
  • 11
  • 27