Let's say such hidden field has genereated:
data-val-number="The field MemberRelationId must be a number."
id="MemberRelationId"
name="MemberRelationId"
type="hidden"
value="3">
As you seem it has a value 3. It means that, user has already set the value for this field.
But, he(she) can also change this value and I must send the new value to the action method.
Also, the main point is that, user can select new value by clickind one of these divs:
Son
Father
Brother
For, now I am manually changing the hidden field value with JQuery after clickin one of these divs
...
$('#MemberRelationId').val($(this).attr("data-value"));
...
But, this way doesn't satisfy me. Is there any better approach in MVC?
What I want to achieve?
I want automatically to get selected div and bind data-value attribute value to MemberRelationId.
Thanks.
Update:
Here is the part from the screenshot:
Talk1:
Why not just use a dropdownlist to bind to your property (or is this a particular UI requirement)?
Talk2:
Yes, this is UI requirement.
Talk3:
Based on you screen shot you could use radio buttons, but it would involve a fair bit of css.
Talk4:
I don't want to use radio buttons here. If I haven't any option, I will continue to change hidden filed value with jquery. So, have I any another option?
Talk5:
Because, Somebody can chnage the property name in the c# class and forget to change MemberRelationId to new id.
Solutions1
The clearest solution is to use radio button with style. In fact, your code act as a radio button; the only difference is the icon-check, but you can emulate the same interface with CSS.
Talk1:
I have updated my question with the required style. IMHO it is not so possible with radio button.
Talk2:
- your opinion is wrong. Unless there is some aspect you haven't mentioned.
Talk3:
Check this sample: code.stephenmorley.org/html-and-css/…. It's perfectly possible to emulate that behaviour through CSS
Talk4:
Ok, I got it. I will give a try to this. I am marking this answer as accepted.