简体   繁体   中英

How to add my own parameters to http get request, generated by <form> in ASP .NET MVC?

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?

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" />
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM