c# - Query Selected Items using checkbox in MVC -


i ask if how possible selected items in checkbox used in making linq query in mvc. have 1 in view in displayed possible options in user select types of softwares used generate reports.

@using (ajax.beginform("create_report", "softwares",             new ajaxoptions             {                 httpmethod = "post",                 insertionmode = insertionmode.replace,                 updatetargetid = "target2"             }))          {              @html.validationsummary(true)              <p>for reports: kindly check softwares create reports.</p><br />             foreach (var item in model) {                  <input type="checkbox" value="@item.software_name" name="software_type"/>@item.software_name                 <br />             }               <input type="submit" value="create report"/>          } 

after that, want selected software types used in query example if user selects adobe pro, adobe illustrator, ms visio, , acrobat, query should go "select software _table software__type = "adobe pro" && software_type ="adobe illustrator && "so fort.

is there ways shorten query using selected items checkbox? appreciated.

assuming post method is

[httppost] public actionresult create_report(string[] software_type) 

then software_type contain array of selected values can use .contains() filter query

var items = db.software.where(s => software_type.contains(s.software_type)) 

side note: remove awful underscores properties , follow normal naming conventions (softwaretype, softwarename, etc or type, name etc since in class named software)


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -