is it possible to pass @Html.DropDownListFor
current value to action link? I want to pass the template value to the Sample
controller with Create
Action. Below code not work because @Model.SurveyTemplate
does not return any value. Is it need JavaScript
to retrieve? Please guide me.
Drop Down List:
@Html.LabelFor(model => model.Survey_Template, "Survey Template")
@Html.DropDownListFor(model => model.Survey_Template, new SelectList(
new List<Object>{
new { value = "Style1" , text = "Style1" },
new { value = "Style2" , text = "Style2" },
new { value = "Style3" , text = "Style3"}
},
"value",
"text",
0))
ActionLink:
@Html.ActionLink("_", "Create", "Sample",
new { template = @Model.Survey_Template },
new { @id = "popup-link", @class = "classname2" })
You have to do this with
JavaScript
, the razor syntax is recognized only on server side. This means that@Model.Survey_Template
will be rendered when user request the page and will have the default value.If you choose to do it with
JavaScript
remember that you need to save the base url and to append parameters to it based on what has been selected.This steps will help you to achieve your desired result:
change
event on your dropdown.value
and construct the new urlhref
) of the action (<a .. />
)Note: I didn't write the code because I want you to surpass yourself.
I think what you try to achive it's a
form
withGET
.