0

I am trying to create filters like in eCommerce website like Amazon, Flipkart.

I have created primary tables for all filters as below.

create table Work
(
id int identity(1,1) Primary Key Not Null,
work_name varchar(30) Not Null,
isSelected bit Default(0),
created_date Datetime default(GETDATE())
)

Now I want to create a CheckBox List so that a user can filter the products according to the selected details.

I have created an Editor Template

@model API.Models.Work

@Html.HiddenFor(x=>x.id)
@Html.HiddenFor(x => x.work_name)
@Html.CheckBoxFor(x=>(bool)x.isSelected)    
@Html.DisplayFor(x=>x.work_name)

I am using the template as

@model IEnumerable<API.Models.Work>

@Html.EditorForModel()

I get the below error

**An exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code

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

How it can be done??

Mayank Bhuvnesh
  • 135
  • 1
  • 4
  • 14
  • Check this http://stackoverflow.com/a/33275507/4868839 – User3250 May 11 '17 at 06:46
  • 2
    Just `@Html.CheckBoxFor(x=>x.isSelected)` (and if your property is nullable, then it needs to be `@Html.EditorFor(x=>x.isSelected)` which will generate a dropdownlist with `True`, `False` and `Not Set` –  May 11 '17 at 08:37
  • @StephenMuecke I tried, but now I get the below error **An exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code Additional information: The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[FadkioskAPI.Models.fad_Work]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[FadkioskAPI.Models.fad_Brand]'.** Also I am using it as a partial view. Will there be any Impact. – Mayank Bhuvnesh May 11 '17 at 13:32
  • Well that is pretty obvious - `fad_Wor‌​k` is not the same as `​fad_Brand` –  May 11 '17 at 21:34
  • And suggest you read [this answer](http://stackoverflow.com/questions/40373595/the-model-item-passed-into-the-dictionary-is-of-type-but-this-dictionary-requ) to understand the causes. –  May 11 '17 at 21:44
  • Thanx buddy......my mistake...thnx a lot... – Mayank Bhuvnesh May 12 '17 at 05:20

0 Answers0