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
Related
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!
This view suppose to show a list of hyperlinks, each pointing to an external URL. The goal is for the user to click one of these links and have their browser open a new tab with the selected URL.
Currently I have the following markup:
#Html.ActionLink("SomeSite", "http://subdomain.mydomain.com/SomeSite")
This markup produces:
http://localhost:58980/AccessInstance/http%3a/subdomain.mydomain.com/SomeSite
instead of :
http://subdomain.mydomain.com/SomeSite
What can I change in my markup to make this work as I expect?
You don't need to use #Html.ActionLink for that. Just use a plain A tag:
SomeSite
Html.ActionLink is specifically for generating links to actions defined in MVC controllers, in the same app. Since you're linking to an absolute URL, you don't need any of the functionality that Html.ActionLink provides.
Two ways :
1. update the database column with full link:
eg SQL:
update ProductTable set ProductLink='http://www.example.com/Product/Mobiles' where ID=123
In asp mvc view
View
2. Hardcode the http part and list from model
View
Hope helps someone.
While a ViewBag is overused and not the best choice most of the time this is something that I had done when inheriting someone else's mvc app to do a quick fix for a URL that I needed to redirect to with a specific dynamically changing querystring parameter
<a target="_parent" href="http://localhost:56332/services/#ViewBag.factory">View Service</a>
Using .NET Core 6
This seems to be the most correct answer:
Link
This will generate the following result:
As you can see at the bottom left corner of the window before clicking the link, the URL address was rendered as it is (NOTE: The cursor was recorded out of place for some reason, that's a ShareX problem, ignore it).
Than link will be directly saved as a nvarchar(750) type (probably any character like type will do the work). No changes to the original link were made before saving it or on reading:
You need to take into account your RouteConfiguration.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}"
because you are specifying the action link as the entire link that you want to redirect.
I would recommend that you use the #rossipedia answer because you can make tricky things like putting a span inside the link
Here to display link that are clickable in index page
<td>
#Html.ActionLink(item.FileName, "../Uploads/Catalogue/"+item.FileName)
</td>
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.
We are using Struts 2 and want a jQuery Grid showing a list of accounts. When a user clicks an account we want to take them to a page specific to that account.
At this point I'm looking for suggestions as to the best way to do this. Currently I'm building a URL server side which I then return but this isn't optimal since I don't have access to <s:url>.
One idea I've had is to combine <s:url> and each row Id on the client side but I haven't found a way to do this. Is there a grid would that allow this? or a better way?
Updated Explanation Attempt:
I am returning a json list to jQuery grid. One column in the grid is a url but I can't build that in the service level. Instead I'd love to have a way to use <s:url> when my json results are returned. Is there anyway to do this?
You cannot use <s:url> client side.
The Struts2-Tags get used serverside
to generate the HTML, so there's
basically no difference if you
construct them yourself or let JSP
construct the HTML.
There's the struts2-jQuery Plugin and with it the jQuery grid plugin. Find out more about it here:
https://code.google.com/p/struts2-jquery/
If you know the actionName and have the ID in the list you're iterating over, you can just code the necessary link yourself (if the object in the list has a getter named getId()):
<a href="http://host:port/webapp/actionName?id=<s:property value='id' />">
Hope that helps, if not please show the code of the page and / or dredefine your question.
There isn't a really straight forward way. Here is the answer to "Struts2 URL buiilding in action for JSON" answered on the struts mailing list:
http://old.nabble.com/Struts2-URL-building-in-action-for-JSON.-td30487914.html
If you get a chance let me know how you implement this.
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.