今天早上我正在解决一个问题。我需要让用户填写一份多步骤表单。表单的某些步骤将具有复选框,当设置为“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/