获取禁用降值倒在asp.net mvc的 [英] Get value of disabled drop down in asp.net mvc

查看:137
本文介绍了获取禁用降值倒在asp.net mvc的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC应用程序。我有我的网页(HTML SELECT)多重下拉列表中,我必须禁用它们,用户通过人去上选择其中之一。当用户帖子回控制器,我得到null作为功能(操作方法)paramters。我搜索,发现HTML不会在表单数据发送残疾人领域的价值。与只读更换disabled属性是行不通的,因为它会使下拉工作。

I have an ASP.NET MVC application. I am having multiple drop-down list in my page (HTML SELECT), I have to disable them, as user goes on selected them one by one. When the user posts it back to the controller, I am getting null as the function (action method) paramters. I searched and found that HTML does not send value of disabled fields in the form data. Replacing disabled attribute with readonly would not work as it would render drop-down working.

我是动态生成的下拉列表中的用户继续使用JavaScript。所以没有一个单一的下拉列表中,但多达用户希望。

I am generating the dropdowns dynamically using javascript as user goes on. So there isn't a single dropdown, but as many as user wants.

有人可以告诉我,我应该怎么获取值?

Can someone please tell me how should I get the values ?

推荐答案

一种可能性是使下拉列表禁用=禁用,包括一个隐藏字段与相同的名称和值,这将使这个值发送到服务器

One possibility is to make the dropdown list disabled="disabled" and include a hidden field with the same name and value which will allow to send this value to the server:

@Html.DropDownListFor(x => x.FooId, Model.Foos, new { disabled = "disabled" })
@Html.HiddenFor(x => x.FooId)

如果你要动态禁用了JavaScript,然后只是简单地禁用后的下拉菜单,隐藏字段的当前选择的值赋给,下拉

If you have to disabled the dropdown dynamically with javascript then simply assign the currently selected value of the dropdown to the hidden field just after disabling it.

这篇关于获取禁用降值倒在asp.net mvc的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆