srujana
srujana

Reputation: 67

how to manage client side state in asp.net mvc3 app

In asp.net we can save post back data using view state i.e for client side state management,i.e default for asp.net web forms.is view state is default for asp.net mvc ?if not how can we save the post back data and is there any replacement of view state in mvc.

Upvotes: 0

Views: 344

Answers (1)

Ravi Gadag
Ravi Gadag

Reputation: 15881

MVC does not uses ViewState. it don't have server side controls to retain the state.

but you can use ViewBag, ViewData to store the values and use it in your views.

public ActionResult Index()
{
    var someList= new List<string>
    {
        "C#, 
        "Java", 
        "PHP"
    };

    ViewData["Languages"] = someList;

    return View();
}

in your view

<ul>
@foreach (var lang in (List<string>)ViewData["Languages"])
{
    <li>
        @lang 
    </li>
}
</ul>

Upvotes: 1

Related Questions