c# - How to send data from view to controller by "id"? -
i put first steps in asp. net , mvc , can not jump on 1 issue.
how can transfer data 2 class = "selectpicker" controller? here's code , attempts to:
model:
public class allocatingcodesinmachinesmodel { public list<string> machinelist { get; set; } public list<string> codescounterlist { get; set; } public int numbersofavaiblecodes { get; set; } }
controller:
[httpget] public actionresult allocatingcodesinmachines() { int numbersofavaiblecodes = //get data db; var codescounter = //get data db.tolist(); var machinelist = //get data db.tolist(); model.machinelist = machinelist; model.codescounterlist = codescounter; model.numbersofavaiblecodes = numbersofavaiblecodes; return view(model); } [httppost] public actionresult allocatingcodesinmachines(allocatingcodesinmachinesmodel model) { var option1 = model.codescounterlist; var option2 = model.machinelist; return view(); } public actionresult testaction(string x, string y) { var option1 = x; var option2 = y; return view("allocatingcodesinmachines"); }
view:
@using swifferr.models.viewmodels @model allocatingcodesinmachinesmodel @{ viewbag.title = "allocatingcodesinmachines"; layout = "~/views/shared/_layout.cshtml"; } <h2>przypisywanie kodów maszyn</h2> @using (html.beginform("allocatingcodesinmachines", "actualcodes", formmethod.post, new { enctype = "multipart/form-data" })) { <div class="row"> <div class="col-sm-12"> <p><h4>dostępne kody</h4></p> <h5 class="text-center">liczba kodów dostępnych przydzielenia: <b>@model.numbersofavaiblecodes</b></h5> <p><h4>przydzielanie kodów</h4></p> <div class="col-sm-4"> <p>liczba kodów przydzielanych maszyny </p> <select id="numbersofcodes" class="selectpicker"> <option>wybierz...</option> @foreach (var item in @model.codescounterlist) { <option value="@item.tostring()">@item.tostring()</option> } <option value="wszystkie">wszystkie</option> </select> </div> <div class="col-sm-4"> <p>maszyna: </p> <select id="machine" class="selectpicker"> <option>wybierz...</option> @foreach (var item in @model.machinelist) { <option value="@item.tostring()">@item.tostring()</option> } </select> </div> <br /><br /> //***1*** <button type="submit" class="btn btn-info">dodaj</button> //***2*** <input type="button" class="btn btn-danger" value="usuń" onclick="location.href='@url.action("testaction", "actualcodes", new {x = "numbersofcode", y = "machine"})'" /> </div> </div> }
i tried, unfortunately did not work out:
1 pass model view controller, not know how "make up" model on side view.
2 tried pass selected items "selectpicker"'s not know how transfer data using id
i know it's base. several days try solve problem , unfortunately fell.
thank in advance advice tips , fixes in thinking , identifying errors in code.
ps. sorry english.
Comments
Post a Comment