In a partial page (a menu) I have this:
@foreach (var category in db.Query("SELECT categoryName FROM Category")) {
<li><a href="#">@category.categoryName</a>
<ul class="submenu">
<form action="/Products/?@Request.QueryString" method="post">
<input type="hidden">
@Html.Hidden("cat", category.categoryName)
</input>
</form>
</ul>
</li>
}
In the page I redirect to, I have this:
if (IsPost) {
if (Request["cat"] != null) {
<p>The category is @Request["cat"]!</p>
}
}
It redirects fine, but I can’t get it to pass the ‘cat’ variable to the page which I redirect to. Normally when I use redirect successfully I use input type=”submit”. The difference here is that these are hyperlinks, which is undoubtedly the reason. I would prefer to keep the hyperlinks.
Any help is appreciated.
In order to submit values in your form tag you have to submit the form. You don’t have any code to submit the form.
Submitting the form is usually achieved by
input type="submit"as you mentioned but other techniques are also possible (for example submitting the form with JavaScript).In your case I wonder if you really have to perform a
POST.What about this approach instead?