简体   繁体   中英

RedirectToAction not passing parameters MVC

I have an action that takes list of model items and delete them, My question is that , why the parameters not getting passed

public ActionResult DeleteMultiple(IEnumerable<QAModel> model)
    {
        _qaService.DeleteMultiple(model);
        long subscriptionId = model.First().SubscriptionId; //value is available here 
        long languageId = model.First().LanguageId;         //value is available here
        return RedirectToAction("Index", new { SubscriptionId =subscriptionId, LanguageId =languageId,Message="Data deleted successfully ."});

    }

//redirection happens but the value getting null inside Index method.

   public ActionResult Index(int? SubscriptionId,int? LanguageId,string Message)
    {



    }

what am i doing wrong can any one please help me for this stuff.

RedirectToAction returns a 302 to the browser which causes another GET request from the browser, so your data is not retained.

If you want to call another method just call the method and avoid the round trip to the browser.

return Index(...)

Try using Route Value Dictionary RouteValueDictionary in the RedirectToAction() Method

C# CODE

public ActionResult DeleteMultiple(IEnumerable<QAModel> model)
    {
        _qaService.DeleteMultiple(model);
        long subscriptionId = model.First().SubscriptionId; //value is available here 
        long languageId = model.First().LanguageId;         //value is available here
        return RedirectToAction("Index",new RouteValueDictionary {{"SubscriptionId",subscriptionId},{"LanguageId",languageId},{"Message","Data deleted successfully ."}, } );

    }

Hope it may help you, Have a nice day.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM