Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

post action for url.action?

Tags:

asp.net-mvc

Here is a line of code in my Controller class:

return JavaScript(String.Format("window.top.location.href='{0}';", Url.Action("MyAction", "MyController")))

Is there a way to make it use the verb=post version of MyAction?

like image 734
Rod Avatar asked Feb 09 '10 16:02

Rod


People also ask

What is action method in URL?

Action method only creates the url not the complete hyperlink, to create hyperlink we need to use Html. ActionLink covered next. To access these querystring values in the action method, we can use Request.QueryString like below. CONTROLLER ACTION METHOD public ActionResult Index() { string com = Request.

What is difference between HTML ActionLink and URL action?

Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.

What is the use of URL action in MVC?

Action(String, String, Object, String)Generates a fully qualified URL to an action method by using the specified action name, controller name, route values, and protocol to use.


1 Answers

You can't use POST by simply navigating to a different URL. (Which is what you'd do by changing location.href.)

Using POST only makes sense when submitting some data. It's not clear from your code what data would actually be POSTed.

If you really want to initiate a POST via javascript try using it to submit a form.

like image 166
Matt Lacey Avatar answered Sep 29 '22 08:09

Matt Lacey