c# - ListBox that updates another part of View -
i want listbox, when submitted, send selected values controller, , response controller used update small piece of view.
the following code able update part of view, , selected values, separately. cannot values listbox while updating part of page:
code able return selected values controller:
public actionresult getinput(listboxmodel mod) { othermodel data = new othermodel(); data.selected = mod; return view("homepage", data); } @model app.models.mainviewmodel @using(html.beginform("getinput", "home", formmethod.post)) { <label for="optionlist">options:</label> @html.listbox("optionlist", model.listboxmod.list) <input type="submit" value="submit"/> }
this code able update part of page, can't data listbox:
public actionresult getinputandupdate(listboxmodel mod) { //get values out of mod , put them in newlist selectedvalues //but no values appear in mod //i can put fake data in selectedvalues , put on page return partialview("partialviewupdate", selectedvalues); }
main view:
@model app.models.mainviewmodel @using(html.beginform("getinputandupdate", "home", formmethod.post)) { <label for="cgselected">care gaps:</label> @html.listbox("cgselected", model.listboxmod.list) <input id="submitbutton" data-url="@url.action("getinputandupdate")" type="submit" value="submit" /> <!-- <input id="loadfrommainframe" data-url="@url.action("caregapsubmitinit", model ??? )" type="submit" value="submit" /> doesn't work! --> //the partial view html gets put here <div id="selectedvaluesitem"></div> }
partial view:
@model app.models.newlist @foreach(var str in model) { @str <br /> }
code update partial view:
$(function () { $("#submitbutton").click(function (e) { e.preventdefault(); var url = $(this).data("url"); $("#selectedvaluesitem").load(url); }); });
if want call getinputandupdate
$(function () { $("#submitbutton").click(function (e) { e.preventdefault(); var url = "@url.action("getinputandupdate")?selectedvalue=" + $("#optionlist").val(); $("#selectedvaluesitem").load(url); });
this
public actionresult getinputandupdate(listboxmodel mod)
becomes this
public actionresult getinputandupdate(string selectedvalue)
Comments
Post a Comment