Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 views
in Technique[技术] by (71.8m points)

c# - 带参数的RedirectToAction(RedirectToAction with parameter)

I have an action I call from an anchor thusly, Site/Controller/Action/ID where ID is an int .

(我有一个我从锚点调用的动作,即Site/Controller/Action/ID ,其中IDint 。)

Later on I need to redirect to this same Action from a Controller.

(稍后我需要从Controller重定向到同一个Action。)

Is there a clever way to do this?

(有一个聪明的方法来做到这一点?)

Currently I'm stashing ID in tempdata, but when you hit f5 to refresh the page again after going back, the tempdata is gone and the page crashes.

(目前我在tempdata中存储了ID ,但是当你回到f5后再次刷新页面时,tempdata就消失了,页面崩溃了。)

  ask by Eric Brown - Cal translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can pass the id as part of the routeValues parameter of the RedirectToAction() method.

(您可以将id作为RedirectToAction()方法的routeValues参数的一部分传递。)

return RedirectToAction("Action", new { id = 99 });

This will cause a redirect to Site/Controller/Action/99.

(这将导致重定向到Site / Controller / Action / 99。)

No need for temp or any kind of view data.

(不需要临时或任何类型的视图数据。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...