Home Save multiselect c#
Reply: 0

Save multiselect c#

user9313 Published in September 21, 2018, 8:02 am

I use cshtml for my select:

 <div class="form-group">
    <label class="control-label col-md-2" for="Ligne">Ligne</label>
    <div class="container">
        <select name="Ligne" id="ligne" class="selectpicker" title="Select something" data-live-search="true"  multiple="multiple">
            @foreach (var item in Model.allLignes)
                <option value=@Html.DisplayFor(modelItem => item.CodeLigne)>@Html.DisplayFor(modelItem => item.CodeLigne)</option>


But when I send form, it saves only one value...

Can you help me?

my controller:

   public ActionResult Create([Bind(Include = "Id,name,begin,end,Ligne")] RT TypeRT)

 cmdPerso.CommandText = "insert into RT (name, begin, end, Ligne, CreateBy) VALUES ('" + TypeRT.name+ "','" + TypeRT.begin+ "','" + TypeRT.end+ "','" + TypeRT.Ligne+ "','" + User.Identity.Name + "')";

I want to use this select expression for edit form.

Thank you in advance.

share|improve this question
  • i think you have to set the "Ligne" as array – Amro Mustafa Feb 14 at 7:54
  • Me too but when i create jquery alert, i have first ligne, second ligne,..., x igne . but I tried doing so by using string list but this ididn't work.. – S.QUIN Feb 14 at 8:06
  • are you using asp.net mvc 5? – Amro Mustafa Feb 14 at 8:08
  • I faced the same issue in my project and the solution was to make the argument as List<Ligne>, this must work with you. – Amro Mustafa Feb 14 at 8:11
  • 1
    Guess what happens if a line contains '); Drop table RT;--. Are you sure this isn't what happened here? Don't use string concatenation to create queries. Use parameterized queries, EF or a microORM like Dapper. – Panagiotis Kanavos Feb 14 at 8:17

2 Answers 2

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.583733 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO