0

I try to make a list of directories in the view. My model is:

public class UploadModel
    {

        [Required]
        [Display(Name = "FormToUpload", ResourceType = typeof(Resources.Entity.Form))]
        public HttpPostedFileBase UploadData { get; set; }
        public string[] Directories { get; set; }


    }

this is the controller:

[HttpGet]
        public ActionResult UploadFile(string designId)
        {
             UploadModel model = new UploadModel();
            string customerSchema = SfsHelpers.StateHelper.GetSchema();
            TemplateLibraryEntry entry = GetTemplateLibraryEntry(designId, customerSchema);
            var path = Path.Combine(Server.MapPath("~/"), entry.FilePath);

            model.Directories = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
            return View(model);
        }

and this is my view:

<div class="form-group">
                                @foreach (var item in Model.Directories )
                                {
                                    @Html.CheckBoxFor(model => true, item)
                                    @Html.LabelFor(model => model.Directories)

                                }

But I get this error:

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

Thank you

I have it now like this:

 public class UploadViewModel
    {

        private UploadModel _uploadModel;

        public string[] Directories { get; set; }

        public UploadViewModel(UploadModel uploadModel)
        {
            _uploadModel = uploadModel;


        }
    }



public class UploadModel
    {

        [Required]
        [Display(Name = "FormToUpload", ResourceType = typeof(Resources.Entity.Form))]
        public HttpPostedFileBase UploadData { get; set; }
        public string[] Directories { get; set; }


    }

and in the view I use the new UploadViewModel: @model SenecaFormsServer.Areas.Dashboard.Models.UploadViewModel

and for the checkboxes:

<div class="form-group">
                                @foreach (var item in Model.Directories )
                                {
                                    @Html.CheckBoxFor(model => true, item)
                                    @Html.LabelFor(model => model.Directories)

                                }                              



                            </div>

and my upload method:

[HttpGet]
        public ActionResult UploadFile(string designId,UploadModel model)
        {
             UploadModel model = new UploadModel();

            UploadViewModel uploadViewModel = new UploadViewModel(model);
            string customerSchema = SfsHelpers.StateHelper.GetSchema();
            TemplateLibraryEntry entry = GetTemplateLibraryEntry(designId, customerSchema);
            var path = Path.Combine(Server.MapPath("~/"), entry.FilePath);

            //model.Directories = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
            uploadViewModel.Directories = Directory.GetFiles(path, "*", SearchOption.AllDirectories);

            return View(uploadViewModel);
        }

but I still get the error:

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

and If I try my view to this:

<div class="form-group">
                                @foreach (var item in Model.Directories )
                                {
                                    @*@Html.CheckBoxFor(model => true, item)*@
                                    @Html.CheckBoxFor(m => m.Directories, new { @checked = "checked" });
                                    @Html.LabelFor(model => model.Directories)

                                }                                    


                            </div>

I get this error: Cannot implicitly convert type 'string[]' to 'bool'

  • possible duplicate of [Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer express](http://stackoverflow.com/questions/21754071/templates-can-be-used-only-with-field-access-property-access-single-dimension) – Gert Arnold Jun 11 '15 at 09:05
  • Thank you. I updated my post – Dimitri Engelen Jun 11 '15 at 09:36

0 Answers0