0

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.

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.