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??

6
  • Check this stackoverflow.com/a/33275507/4868839 Commented May 11, 2017 at 6: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 Commented May 11, 2017 at 8: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.List1[FadkioskAPI.Models.fad_Work]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[FadkioskAPI.Models.fad_Brand]'. Also I am using it as a partial view. Will there be any Impact. Commented May 11, 2017 at 13:32
  • Well that is pretty obvious - fad_Wor‌​k is not the same as ​fad_Brand Commented May 11, 2017 at 21:34
  • And suggest you read this answer to understand the causes. Commented May 11, 2017 at 21:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.