1

I have a form in my view:

@using(Html.BeginForm("Details", "Category", FormMethod.Get))
{
    <input type="text" name="param1" />
    <input type="submit" value="OK" />
}

This form is on page with parameter ~/category/details?view=list I get value of view parameter from route query string and want to pass it to request generated by my form. I want to have request query string like ?param1=inputedText&view=list instead of just ?param1=inputedText. How can I do that without adding, for example, hidden input to my form and setting view value to it?

tereško
  • 58,060
  • 25
  • 98
  • 150
Dmytro
  • 16,668
  • 27
  • 80
  • 130
  • why you don't wish to add hidden field? you can use `Html.BeginForm` overload that accepts route value dictionary too: `@using(Html.BeginForm("Index", "Home", new { view = "list" }, FormMethod.Get))`. Also you could theoretically use javascript for that, but question remains - what is the reasoning? – Giedrius Sep 05 '12 at 07:23
  • There already was an answer about Html.BeginForm overload, but author probably deleted it, I explained already, it doesn't work. It generates form with "action=~\action?view=list" attribute, but when I submit form, only input form values are submited, and no view parameter appears in result route query string. – Dmytro Sep 05 '12 at 07:40
  • And I don't want to use hidden inputs because first of all form is designed by my teammate and second of all I suggest it would be incorrect in meaning of architecture to redesign form that way. – Dmytro Sep 05 '12 at 07:43
  • 1
    You're right about route values being reset on submit, but I still don't get the reasoning. May be you mean, that view parameter value is static and you have many forms that need it and you don't wish to edit them all? I not afraid of javascript you may try these - http://stackoverflow.com/questions/993834/adding-post-parameters-before-submit or http://stackoverflow.com/questions/1090948/change-url-parameters-with-jquery or http://stackoverflow.com/questions/3761051/adding-dynamic-parameters-with-html-beginform-and-jquery-submit but imho that needs reasoning - hidden input is much less complex – Giedrius Sep 05 '12 at 07:53

1 Answers1

0
public ActionResult Details(string view )
{
    ViewBag.view = view ;
       return View();
}

public ActionResult Details(string view ,string param1)
{
    ViewBag.view = view ;
       return View();
}

This approch may help you

@using(Html.BeginForm("Details", "Category", FormMethod.Get))
{ 
    <input type="Hidden" name="view" value=ViewBag.view >
    <input type="text" name="param1" />
    <input type="submit" value="OK" />
}