2

How access one controller data in another controller.

I'm using ASP.NET MVC 4. I am trying to access one controller properties in another controller. I'm not getting this. I'm not sure if this is possible?

Here are my formcontroller properties:

public string CorticonServiceEndpoint { get; set; }

    public string CorticonServiceName { get; set; }

    public string CorticonServiceMajorVersion { get; set; }

    public string CorticonServiceMinorVersion { get; set; }

And my form controller doesn’t have Action instead it has ajax submit.

        [StandaloneResponseFilter]
    [HttpPost]
    public JsonResult AjaxSubmit(FormCollection collection)
    {
        SubmitStatus submitedSuccessfully = this.Model.TrySubmitForm(collection, this.Request.Files, this.Request.UserHostAddress);
        if (submitedSuccessfully != SubmitStatus.Success && this.Model.RaiseBeforeFormActionEvent())
            return this.Json((object)new
            {
                success = false,
                error = this.Model.GetSubmitMessage(submitedSuccessfully)
            });
        return this.Json((object)new
        {
            success = true,
            error = string.Empty
        });
    }

Here is one more controller (ResponseController)and from this controller I want to read form controller properties.

[HttpPost]
    public ActionResult Index(FormCollection formCollection)
    {

        var viewModel = this.Model.GetViewModel(payLoad);
        return View(CorticonResponseModel.viewName, viewModel);
    }

On form submit,ActionResult with HttpPost attribute will be triggered and then I need form controller properties for further processing.

I know using TempData,session and etc.. we can pass controller data from one action to another action in two controllers. Is it possible to access FormController properties in Response controller?

For better understanding I have shared a video at below URL

https://drive.google.com/open?id=0B1Z7d8OTSWR4NDFadXVueUt2MFE

Balanjaneyulu K
  • 3,660
  • 5
  • 24
  • 45
  • 1
    Sorry ! I am confused. What are you really trying to do ? Rememeber Http requests are state less. and for every request a new instance of your controller will be created. So i guess you need to post the value needed from your form. – Shyju Jul 28 '16 at 17:19
  • yes, After posting I want to read those properties for further processing. – Balanjaneyulu K Jul 28 '16 at 17:20
  • Still not following what you want ? Who sets that values ? Was those set via another Http request ? – Shyju Jul 28 '16 at 17:21
  • those properties will set on form designer and after submitting I was triggering another controller(responseController). If you want I will share a video which explains exact issue. – Balanjaneyulu K Jul 28 '16 at 17:22
  • What is **form designer** ? Please update the question with relevant code & expected behaviour. – Shyju Jul 28 '16 at 17:23
  • Sorry Shyju. I feel , I am confusing. give me couple of minutes. i will share a video. Hope this helps. – Balanjaneyulu K Jul 28 '16 at 17:24
  • Possible duplicate of [Passing data between different controller action methods](http://stackoverflow.com/questions/15385442/passing-data-between-different-controller-action-methods) – Jasen Jul 28 '16 at 17:41
  • Hi Jasen correct but I want the reverse process. – Balanjaneyulu K Jul 28 '16 at 17:43
  • You can understand clearly please watch this : https://drive.google.com/open?id=0B1Z7d8OTSWR4NDFadXVueUt2MFE – Balanjaneyulu K Jul 28 '16 at 17:45
  • 1
    use redirect to action and pass those properties as parameter Hope it will help – Pankaj Gupta Jul 29 '16 at 06:01

0 Answers0