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 sho开发者_如何学Cw ViewModel as an option.
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
I know this is a bit late, but it may be better practice to use the following:
ModelState.AddModelError("", "Update Failure");
Then, in your view:
@Html.ValidationSummary(true)
Instead of ViewModel.UpdateError = "Update Failure";
Use
ViewBag.UpdateError = "Update Failure";
And In your View, Use this
@ViewBag.UpdateError
精彩评论