Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewModel MVC 3

I am new to MVC. I am going through the following tutorial.

I am on the portion where it calls for the following code

[HttpPost]
public ViewResult Edit(UserModel um) 
{

  if (!TryUpdateModel(um)) 
  {
    ViewModel.updateError = "Update Failure";
    return View(um);
  }

  // ToDo: add persistent to DB.
  _usrs.Update(um);
  return View("Details", um);
}

When I attempt to use ViewModel I receive an error:

"The name ViewModel does not exist in the current context."

Intellisense does not show ViewModel as an option.

like image 776
dan_vitch Avatar asked Feb 27 '11 07:02

dan_vitch


People also ask

What is a ViewModel MVC?

In ASP.NET MVC, ViewModel is a class that contains the fields which are represented in the strongly-typed view. It is used to pass data from controller to strongly-typed view.

What is a ViewModel used for?

The ViewModel class is designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations.


1 Answers

ViewModel does not exist for a mvc 3 controller. I think what you are looking to use instead is the following:

ViewBag.UpdateError = "Update Failure";

Then in your view:

@View.UpdateError
like image 129
Mike Geise Avatar answered Nov 15 '22 08:11

Mike Geise