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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With