How to retrieve a property value from modelstate

advertisements

How can I retrieve a property value from modelstate in httppost action.

Below is the code, I used to retrive the hidden id field from modelstate. But is it not possible to have strongly typed version to get value. Like, if property name is modified, prompting a compile time error.

Could anyone please explain difference between "AttemptedValue" and "RawValue".


 ModelState state;
 if (ModelState.TryGetValue("id", out state))
 {
     string value = state.Value.AttemptedValue.ToString();
 }


Attempted value is used by the framework and it contains concatenated list of values. In my case, since it is id field, I am going ahead with attempted value. Below link has more information on this.

http://forums.asp.net/t/1571473.aspx/1?MVC+2+Custom+ModelBinder+and+storing+the+attempted+value+for+the+view