Which approach is more preferrable when changing just a single value in model? Aesthetically-speaking and performance-wise.
Looks clean(albeit with the overhead of pushing the entire model again to the View
):
ModelState.Remove("Name");
guestResponse.Name = "John";
return View(guestResponse);
Looks performant:
ModelState["Name"] = new ModelState { Value = new ValueProviderResult("Paul", null, null) };
return View();
If changing the model state dictionary is performant and can do this...
ModelState["Name"] = "George";
...I will use that over the first code(with Remove
and return View(guestResponse)
), but unfortunately, ModelState need to be assigned with ModelState and ValueProviderResult. It looks ugly to me.
Which one do you use when changing the model's property value(s) in controller?