I’m fairly new to asp.net mvc and I have a question. Example model:
public class FooModel
{
public string StrA {get; set;}
public string StrB {get; set;}
}
How can I do something like this: pass model to view (model with StrA filled, StrB empty), update StrB of my model (StrA filled, StrB filled) and then submit it to my action with both StrA and StrB filled (by default I will pass new instance of model with only StrB filled and my previous value of StrA will vanish).
I know I can use HiddenFor, but is there any other way to do that?
In your POST action you could fetch the value of the
StrAproperty from the same place you fetched it in your GET action. This way you don’t need to use a hidden field to persist it.For example:
Now in the view you could only have an input field for
StrBinside the form which will allow the user to modify its value: