Reputation: 17467
I have a form in Razor I am checking for the post in a form in a Razor macro. I am checking for the form being posted with the in built IsPost variable. I need to get the value from the form (the url) and then the page to the value.
form action="" method="POST">
<select>
<option>Please Select</option>
@foreach(var item in @Model.events){
<option value="@item.Url">@item.Name</option>
}
</select>
<button id="SubmitForm" type="submit">Submit Enquiry</button>
<p>@Message</p>
</form>
Upvotes: 2
Views: 4216
Reputation: 10942
You're going to want to give your select
an id, but you should be able to accomplish what you want by accessing the value of the select
using Request
collection and then redirecting to the selected url with a Response.Redirect()
.
Example:
if (IsPost)
{
string url = Request["selectId"] as string;
if (!string.IsNullOrEmpty(url))
{
Response.Redirect(url);
}
}
Upvotes: 1