I am working in asp.net MVC , i face issue when checkbox is clicked then fileupload shows otherwise not shown
How can i solve this issue?
I am working in asp.net MVC , i face issue when checkbox is clicked then fileupload shows otherwise not shown
How can i solve this issue?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal JoshiRank #377 · 6.7K reputationPosted Oct 30, 2023, 6:35 AM EDT
Hello Garima,
As it's in foreach loop. it will create duplicate IDs enclcheck for check box control.
I would suggest making it by class instead of id.
Also, you need to handle textboxfor/file upload control hide and show by class name. otherwise, it will work for only a particular ID (i.e. upfile3)
Thanks
Vishal Joshi
Garima BansalRank #1,554 · 1K reputationPosted Oct 25, 2023, 5:49 AM EDT
Here is the code
Amit KumarRank #459 · 5.4K reputationPosted Oct 25, 2023, 9:34 AM EDT
Hi Garima,
You can do it using two ways.
1) Server Side
2) Client client (Jquery)
I suggest please go with cleint side.
use this code. It will help you.
suppose your check box is
and file upload is
use below jquery code it will work for you.
$("#isCheck").on('change', function() {
if ($("#isCheck").is(':checked'))
$("#myfile").css("display", "block");
else {
$("#myfile").css("display", "none");
}
});
Garima BansalRank #1,554 · 1K reputationPosted Oct 25, 2023, 3:33 PM EDT
i used it fro one of the fileupload
$(function () { $("#enclcheck").click(function () { if ($(this).is(':checked')) { $("#upfile3").show(); } else { $("#upfile3").hide(); } }); });but not works.
Actually i have multiple fileupload, below is the code can you help me out
@foreach (var item in Model.ensredetailslist) { @if (item.ischecked) { } else { } @if (item.ensuretypes == 1) { @item.ensurenames @Html.ActionLink("Fillup", "form1a", "pdfgeneration", new { @id = @item.ensuretypes, @desc = @item.ensurenames, @applnno = @Model.applnno }, htmlAttributes: new { style = "background-color: #5f9ea0; color: #FFF" }) } else if (item.ensuretypes == 2) { @item.ensurenames @if (item.ischecked) { View Delete } else { @Html.TextBoxFor(model => model.approveddocument, new { type = "file", name = "files", id = "upfile3" }) } @Html.HiddenFor(model => item.ensuretypes, new { id = "enclotype3" }) } else if (item.ensuretypes == 3) { @item.ensurenames @if (item.ischecked) { View Delete } else { @Html.TextBoxFor(model => model.approveddocument, new { type = "file", name = "files", id = "upfile7" }) } @Html.HiddenFor(model => item.ensuretypes, new { id = "enclotype7" }) } else if (item.ensuretypes == 4) { @item.ensurenames @if (item.ischecked) { View Delete } else { @Html.TextBoxFor(model => model.approveddocument, new { type = "file", name = "files", id = "upfile1" }) } @Html.HiddenFor(model => model.enclosurenames, new { id = "ensdesc1" }) @Html.HiddenFor(model => item.ensuretypes, new { id = "enclotype1" }) }