دنبال کننده ها

۱۳۹۶ اسفند ۹, چهارشنبه

c# - Access selected item from drop down from two different forms

[ad_1]



I have one drop down list:



@Html.DropDownListFor(m => m.SelectedPassType, Model.PassTypeList)


And two buttons which post back to action methods:



The clear button:



@using (Html.BeginForm("ClearData", "MemberPass", FormMethod.Post))

<div>
@foreach (var property in ViewData.ModelMetadata.Properties)

<input type="hidden" value="@property.Model" name="@property.PropertyName" />

</div>
<button>Clear</button>



The submit button:



@using (Html.BeginForm("Submit", "MemberPass", FormMethod.Post))

<div>
@foreach (var property in ViewData.ModelMetadata.Properties)

<input type="hidden" value="@property.Model" name="@property.PropertyName" />

</div>
<button>Submit</button>



I'd like to make sure all the model's properties are sent to the action method which is why I'm using the @foreach loop.
However of course this won't work for the drop down because the page's HTML is generated before the user selects the drop down menu item.



How can I get the value of the currently selected item in the drop down and make sure it's posted back to the two form's action methods?




[ad_2]

لینک منبع