How to transfer a value from one action to another action with the same controller

Hi, I am developing an application in MVC3. and I'm stuck in one place. Each time the control goes into action IIndex1, its argument value becomes 0. But it must be the same as the value in the IIndexaction argument . I used the session, ViewBag, ViewData, but my problem remains. Please suggest me.
        public ActionResult GetMDN(string msisdn)
        {
            number = msisdn.Substring(0, msisdn.IndexOf('$'));
            if (number.ToLower() != "unknown" && number.Length == 12)
            {
                number = number.Remove(0, 2);
            }
            Session["msdresponse"] = number;
            Session["moptr"] = msisdn.Substring(msisdn.LastIndexOf('$') + 1);
            number = msisdn;
            int sngid=int.Parse(ViewData["isongid"].ToString());
            return RedirectToAction("IIndex1", new { iid = sngid });
        }

        public ActionResult IIndex(int id)
        {
            ViewBag.isongid = id;
            ViewData["isongid"] = id;
            Response.Redirect("http:XXXXXXXXXXXXXXXX");
            return RedirectToAction("GetMDN");
        }

        public ActionResult IIndex1(int iid)
        {

        }
+4
source share
2 answers

You can use TempData. You can transfer all types of data between actions, regardless of whether they are in the same controller or not. Your code should look something like this:

    public ActionResult GetMDN(string msisdn)
    {
        int sngid=10;

        TempData["ID"] = sngid;

        return RedirectToAction("IIndex");
    }

    public ActionResult IIndex()
    {

        int id = Convert.ToInt32(TempData["ID"]);// id will be 10;
    }
+16

Source: https://habr.com/ru/post/1540691/


All Articles