Click here to Skip to main content
15,884,816 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I am using TempData for storing and fetching values from controller to View. It's working fine when I am running my MVC3 application using visual studio but it stops working when I deploy it on server can anybody help on this issue ? Thanks in advance

As I am using in a controller


C#
TempData["Save"] = "Success";


And in a view

C#
@if (TempData["Save"] != null)
{
    <span style="color: red;margin-removed46%;" >Entries saved sucessfully</span> 
}


It shows proper values when running with Visual studio and Doesn't work when I deploy this controller and view on server.

When I run on local visual studio it shows as span with values Entries saved sucessfully but when i deploy the view and controller on server the span is missing!!!
Posted
Updated 23-Aug-13 1:52am
v4
Comments
[no name] 23-Aug-13 6:00am    
"not working" means absolutely nothing when you are trying to describe a technical problem. You need to supply relevant code, error messages, a much better description, stack traces, etc if you expect someone to be able to help you.
Madhav Hatwalne 23-Aug-13 6:05am    
Now check!
[no name] 23-Aug-13 6:32am    
Okay.... "not working" is now "doesn't work". How do you expect people to know what "doesn't work" means? Do you call your mechanic on the phone and tell him "car broke" and expect that he can figure out what that means?
Madhav Hatwalne 23-Aug-13 7:47am    
It's Blank very simple. No errors nothing. It suppose to show span but it's not showing!!!!!
Madhav Hatwalne 23-Aug-13 7:49am    
It is enough for you or more simple words required ?

1. TempData is meant to be a very short-lived instance, and you should only use it
during the current and the subsequent requests only.

2. Since TempData works this way, you need to know for sure what the next request will be, and
redirecting to another view is the only time you can guarantee this.

3. Therefore, the only scenario where using TempData will reliably work is when
you are redirecting.This is because a redirect kills the current request , then creates a
new request on the server to serve the redirected view.

4. Simply said, Asp.Net MVC TempData dictionary is used to share data between
controller actions.

I have written a article about this :

http://sampathloku.blogspot.com/2012/09/how-to-use-aspnet-mvc-tempdata-properly.html[^]


So don't use TempData for carrign data from controller to View.For that you can use ViewBag.

Controller

SQL
public ActionResult Index()
{
    ViewBag.Name = "Hajan";
    ViewBag.Age = 25;
    return View();
}




View


XML
<p>
    My name is
    <b><%: ViewBag.Name %></b>,
    <b><%: ViewBag.Age %></b> years old.
    <br />
    I like the following colors:
</p>



More info :

http://weblogs.asp.net/hajan/archive/2010/12/11/viewbag-dynamic-in-asp-net-mvc-3-rc-2.aspx[^]

I hope this will help to you.
 
Share this answer
 
v3
Thanks all for your comments but it was an deployment issue I posted Controller and views on server and forgotten to deploy dll as I am used to with Website deployments!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900