I have a form view that uses a ViewModel. The new view is displayed in the "New" action. When this form is submitted, I submit the information to the Add action.
If all the actions in the database are successful, I want to update the view. I create a new viewmodel instance from within the Add action and return a View (New, viewModel). This does not update my mind. All old values (which were presented) remain in the view. Is there a way to refresh the page without the RedirectToAction method.
I read in another post that ModelState.Clear should not be used as it may have an undesirable result.
Thank,
Mar
Edit 1 - Added code
New
public ActionResult New(string id)
{
var sysId= new Guid(id);
.......
........
string Details = pDto.Name + "(" + pDto.Code + ")";
var vm= new ViewModel(id);
vm.Details = Details;
return View(vm);
}
public ActionResult Add(ViewModel vm)
{
ViewModel vm= vm;
if (ModelState.IsValid)
{
var dto= _qRepository.GetFeaturesBy(viewModel.Code);
if (dto!= null)
{
ModelState.AddModelError("Code", "Code is already in Use.");
return View("New", viewModel);
}
_productService.AddFeature(..........);
vm= new ViewModel(vm.pId) { Message = "Code" + viewModel.Code + " was added ......", Details = vm.Details };
}
return View ("New", vm);
}