asp.net mvc - Using one dropdownlist for two different forms in ASP MVC -


using mvc4, have drop-down list contains value user may select. have 2 different actions pass value into. how accomplish this, if possible?

view:

@using (html.beginform("action1", "controller", formmethod.post, new formcollection())) {    @html.dropdownlist("item", model.getlistvalues(model.items))    <input type="submit" value="goto action1"> }  @using (html.beginform("action2", "controller", formmethod.post, new formcollection())) {    <input type="submit" value="goto action2"> } 

controller:

public task<actionresult> action1(string item) {   //logic }  public task<actionresult> action2(string item) {   //logic } 

right now, code allow me pass in value in dropdown first form, how include in second form? might involve use of @html.hiddenfor? don't want duplicate drop-down list.

with jquery, things possible.

as mentioned, add hidden field second form. then, add jquery script update field whenever dropdown changes. you'll need update item names aren't duplicates, other that, existing code work.

$("#itemdropdown").change(function () {     $("#itemhidden").val($("#itemdropdown").val()); }); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

java - How to create Table using Apache PDFBox -

c# - Attempting to upload to FTP: System.Net.WebException: System error -