0

In asp.net MVC3, how I can implement an input what it does GET using query parameters of source web page? I prefer don´t use hidden inputs.

Update. For example, my page contains a query parameter id=54, when input causes a GET, I need destination controller/action receive this query parameter.

// could i change it for include query parameters of source page?
using (Html.BeginForm("Action", "Controller", FormMethod.Get))
{   
  <input type="submit" value="Text" onclick="submit"/>
}
2
  • Please rephrase the question, I don't understand it. You want to implement an alternative to hidden inputs when posting forms in ASP.NET MVC 3? Commented Feb 1, 2012 at 13:50
  • It seems no possible: stackoverflow.com/questions/1116019/… Could somebody confirm? Commented Feb 1, 2012 at 16:21

3 Answers 3

1

The solution to your problem is exactly this:

Html.BeginForm("Action", "Controller", new { id = 54 }, FormMethod.Get)
Sign up to request clarification or add additional context in comments.

6 Comments

Note, query parameters in action of forms are ignored. w3.org/TR/html401/interact/forms.html#form-data-processing
I'm positive that this works and I didn't find any reason not to in your link. The form in the answer will submit to somewhere like: /Controller/Action?id=54. What's the problem?
If you, use HTTP GET and use query parameters in action of forms then browser doesn´t send the query parameters. You can test using fiddler: <html> <body> <form action="localhost?id=1" method="get"> <input type="submit" value="submit" /> </form> </body> </html>
Then why does this work? Did you try this? Then how do you submit a form in a page like the old days of site.tld/somepath?p=1&m=45 ?
do you use hidden inputs for parameters?
|
0

I would use TempData to store this kind of temporary data, tempdata is saved for one routetrip after its being read it should be disposed unless keep method is used.

Comments

0

Use this: ControllerContext.HttpContext.Request.UrlReferrer.ToString(); If it will not help, you can use global filter (register it at global.asax)

protected void Application_Start()
{
    GlobalFilters.Filters.Add(new PreviousUrlSavingFilter())
}

public class PreviousUrlSavingFilter: ActionFilterAttribute
{
     protected override OnActionExecuted(ActionExecutedContext filterContext)
     {
         filterContext.HttpContext.Session["PreviousRouteData"] = filterContext.RouteData;
     }

     // use this property to access previous page route data
     public static RouteData PreviousUrlData
     {
         return (RouteData) HttpContext.Current.Session["PreviousRouteData"];
     }
}

If you want to edit current url using previous url parameters, this link will be helpful to you: https://stackoverflow.com/a/4222584/571203

3 Comments

Thx for you answer. Good trick ;-) but I think there´ll be another option, I think I prefer hidden inputs to your answer. Some proxies could remove urlreferrer and I only want avoid extra hidden inputs.
So, can i change url that input GET for including query parameters?
Dont understand you. Can you explain in details what input you want and what you want to change?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.