asp.net mvc 2 - How do I pass data between two controllers? -


In my specific example, I need to get an error on a controller on an controller where it will be displayed. Here is a test case that I had set. I have tried tempadata, watchdata and session. I saw one more thing that maybe I am redirecting it. When I put a breakpoint on the receiver controller, if I go to it then I hit the breakpoint, but it is never hit on the redirect.

Send Administrator Action

  Public Actions New () {Session ["Information"] = "There was an Error"; Session ["noticeclass"] = "error"; Redirect Action ("Index", "Home"); }  

Then the recipient is the controller here:

  public performance index () {// handle action return view (); }  

Then any error or notice is found in a partial view

  & lt;% @ Control language = "C #" Inherits = " System.Web Mvc.ViewUserControl & LT; Dynamic & gt; "& Gt%; & Lt;% string message = ""; String class = "hidden"; If (see data ["notice"]! = Null & viewData ["information"] = "") {message = (string) view data ["notice"]; Class = (string) View Data ["NoticeClass"]; } If (session ["information"]! = Null & session ["information"] = "") {message = (string) session ["information"]; Class = (string) session ["noticeclass"]; Session ["notice"] = null; } Response.Write ("& lt; div class = \" "+ class +" \ "id = \" error_div \ "& gt; & lt; span id = \" error_span \ "& gt;" + message + " & Lt; / span & gt; & lt; / div & gt; "); & Gt%; Update: First of all, sorry, but I still can not get a clear picture -  

Considering that you want to get data in the action of an administrator, send it to the operation of another controller and then present it in a partial view. You can use sessions to get the values ​​on the other controller as you store it .... but I think that can work in your case again .. for redirection -

  return redirection action ("Action", "Controller", route value)  

I think you know about tempdata and watchdata Should read more and not give it anything Do not use ViewData unless the value that I can not see in your code and you are still using it.

Tempdata Store Price Per Request .... So a new request means that it will lose value. Take a look if you want to exceed the values ​​using tempdata.

Therefore, in your case if you are only looking for the string then do something like this -

  public action new () {string str = "was an error" ; Return Redirect Reactions ("Index", String); } Public Performance Index (string str) {Response.Write (str); See Return (); }  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -