Asp.Net MVC Form[GET]. Correct action url - asp.net-mvc

I've got search form, which contains checkboxlist which is binded to my model. So when I set GET method to form I got long url:
(I even have exception:
The length of the query string for this request exceeds the configured maxQueryStringLength value.)
it's expecting, [0].IsSelected=false&[0].Id=6&[1].IsSelected=false...
But I would like url like this
www.domain.com/Action/Comma-separated-selected-idx
for example:
www.domain.com/Search/1,6,7
How can I fix,edit form get action? Thanks

I would do a POST instead, then redirect to the URL you desire.
OR
You could capture the form with some JavaScript and build the URL there.

agreed, POST or JS are your best options, I'd opt for a POST.

Related

Posting to a web form and catching results from JavaScript code

How would I go about achieving the following
I have some HTML data triggered from an Evernote new note action
I need to pass this HTML string to a website via an http post with form variables
I then need to catch the resulting web page text in a variable to use in my next action.
For clarity the website simply takes some HTML and converts it to markdown passing it back out as the body of the resulting page
Regards in advance
Dan
Sweet! So I've got this working. In my example, text is some html I pulled out of a dummy previous step:
The output is:
Which has the markdown as a key. If you want to tweak other data based on the api params, you can do that as GET params below html
​Let me know if you've got any other questions!

Handling routes in asp.net mvc

I have an action that I want to use to handle the saving of a report for a project and a sub project. The code to run is essentially the same so I thought I could create a custom save action and then specify the routes; however, it doesn't seem to be working as expected.
My action signature is
[Route("Project/{projectNumber}/Reports/ProjectHoursAndCosts/save")]
[Route("Project/{projectNumber}/Reports/ProjectHoursAndCosts/{subProjectNumber}/save")]
public ActionResult ProjectHoursAndCosts(ProjectHoursAndCostsViewModel projectHoursAndCostsViewModel)
If I remove one of the routes it works as expected. Any ideas?
I've set the action in form
(Html.BeginForm("Save", "Reports"))
If my initial url is
http://somehost/somewebapp/Project/61033651/Reports/ProjectHoursAndCosts
it seems to work ok, however if I try to save a sub project which has the url
http://somehost/somewebapp/Project/61033651/Reports/ProjectHoursAndCosts/61033651-1
When I hit save the url changes back to
http://somehost/somewebapp/Project/61033651/Reports/ProjectHoursAndCosts/save
I would expect it to submit to the url
http://somehost/somewebapp/Project/61033651/Reports/ProjectHoursAndCosts/61033651-1/save
Update
Looking at the raw form element in the html page I can see that even though the url is http://somehost/somewebapp/Project/61033651/Reports/ProjectHoursAndCosts/61033651-1, the actual post url is still somewebapp/Project/61033651/Reports/ProjectHoursAndCosts/save
How can I change the action attribute of the form to use the correct url?

ASP.NET MVC - How to get an URL instead of an action link?

I want to embed a URL in an applet parameter.
The only way I know to create automatically the URL is Html.ActionLink(), but I want only the inner HREF attribute, not the whole link.
Is there another way to get what I wan't, other that using Regex on the output of ActionLink() to get the HREF attribute?
To get only the URL, you can use Url.Action() instead of Html.ActionLink().
It has a number of overloads, so you can give it the name of a route, or the name of the action and the controller, or a number of other options.
Example:
Url.Action("YourAction", "YourController")

Testing ASP.NET MVC2 service using Firefox Poster add-on

I'm trying to create a simple service using ASP.NET MVC2. I'm using Poster add-on 1 for Firefox, but when I use POST by filling parameters using Poster, I can't reach them on the controller, here's the line I use:
string parameter = Request.Form["an_example_parameter"];
Am I doing something wrong? Any help on this? Thanks!
Ok, I figured it out.
On a post the parameters are not added to the URL. If you want them to be sent as the body of the post (e.g.
like a form post), use the "Parameter Body" button to create the content.
http://code.google.com/p/poster-extension/issues/detail?id=43

How to post a form with MVC controller?

How do I post a form to an external site using an ASP.NET MVC controller?
EDIT: Ok... I have a view with some data on it. After the user completes the form I need to do a postback with a specified form format to an external site (like for paypal). After I posted the constructed form I need to redirect the action to a new view
You have to do the POST on the server-side..
of which this guy has written a helper class to do Http Post in C# (pastebin-ed). Check it out.
Send the post with the PostSubmitter class and just render your view normally.
Basically, in situation like this one would create a HttpWebRequest, set Method to post and write the post data to the request stream. But the linked code already does that for you in a nice and cozy way.
So no need rewire anything.
You can just manually set the action in the form tag to wherever you want to post to...
edit -
That is to say that you should manually create the form tag..
Instead of:
<% using (Html.Form<Controller>("Action", c => c.Method())) { %>
You should use:
<form action="http://www.someotherwebsite.com/action">
How about sending a redirect to the browser.

Resources