c# - 如果用户将复选框设置为 true,如何动态显示上传按钮?

标签 c# jquery asp.net-mvc-3 uploadify

今天早上我正在解决一个问题。我需要让用户填写一份多步骤表单。表单的某些步骤将具有复选框,当设置为“true”时,应动态显示上传按钮。

这是相对容易做到的事情吗?

更新 - 现在你们都会恨我。

我的 razor View 只有一行来生成每个步骤。

@Html.EditorFor(x => currentStep,null,"")

因此,我不认为以直接方式添加 jquery 是一个选项。

我的 ViewModel 是这样工作的。它根据实现 IStepViewModel 接口(interface)的类动态生成步骤列表。那么...您也许看到了这个问题吗?

  [Serializable]
    public class WizardViewModel
    {
        
        public String AccountNumber { get; set; }
        public int CurrentStepIndex { get; set; }
        public Boolean IsInitialized { get { return _isInitialized; } }

        public IList<IStepViewModel> Steps { get; set; }

        private Boolean _isInitialized = false;

        public void Initialize()
        {
            try
            {
                Steps = typeof(IStepViewModel)
                    .Assembly.GetTypes().Where(t => !t.IsAbstract && typeof(UploadViewModel).IsAssignableFrom(t)).Select(t => (IStepViewModel)Activator.CreateInstance(t)).ToList();
                _isInitialized = true;
                //rewrite this.  get the profile and wire them up or something.
                this.AccountNumber = Tangible.Profiles.DR405Profile.CurrentUser.TangiblePropertyId;

            }
            catch (Exception e)
            {

                _isInitialized = false;
            }
        }
    }

最佳答案

是的,您可以这样做(最简单的是,如果您显示您的标记,我们可以提供更详细的答案,以便您可以使用适用于所有按钮的单个处理程序):

$('#checkbox').change(function(){
    if($(this).is(':checked')){
        $('#button').show()
    }else{
        $('#button').hide()
    }
});

关于c# - 如果用户将复选框设置为 true,如何动态显示上传按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6859346/

相关文章:

C# 接口(interface)和泛型列表

php - 下载文件前的javascript检查

asp.net-mvc-3 - MVC编辑器问题对于命名模板

asp.net-mvc-3 - ASP.NET MVC Razor呈现不编码的SelectList

c# - 如何将 IEnumerable(无类型)转换为 IQueryable<T>?

c# - 是否可以解决这种装配不匹配的情况?还是这个问题无法解决?

c# - 绑定(bind)到来自两个不同类的属性值

脚本加载后的 JQuery 高度

javascript - 将多个 div 元素包裹在同一个类中

asp.net-mvc-3 - MVC3 Razor Ajax.ActionLink不会使用POST方法