获取html元素隐藏属性值,在Asp.Net MVC中进行绑定之前,获取所需的html元素的属性值并设置为隐藏字段...

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:

6e1cd42f0db5ecf3d6e1bd5b347119ee.png

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值