[英]RedirectToAction not passing parameters MVC
我有一个需要采取模型项列表并将其删除的操作,我的问题是,为什么未传递参数
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 ."});
}
//发生重定向,但Index方法中的值变为空。
public ActionResult Index(int? SubscriptionId,int? LanguageId,string Message)
{
}
我做错了什么,任何人都可以帮我这个忙。
RedirectToAction向浏览器返回302,这导致浏览器发出另一个GET请求,因此不会保留您的数据。
如果要调用另一个方法,只需调用该方法,避免往返浏览器。
return Index(...)
尝试在RedirectToAction()方法中使用路由值字典RouteValueDictionary
C#代码
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 ."}, } );
}
希望对您有帮助,祝您有美好的一天。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.