I have an MVC3 C#.NET web app and need to call a view using Html.ActionLink. I can't tell from the documentation if I can specify the POST or GET. Below is my HTML, is there a way to specify GET or POST?
#Html.ActionLink("Create New", "Edit", "Subtask",
new {Id = ViewBag.Id, Command="CreateHourEntry"}, null)
If you want a post use Ajax.ActionLink but be aware it's an Ajax post. You could easily use jquery to cause your existing link to cause a form post but this functionality is not included in Html.ActionLink.
See
ASP.NET MVC ActionLink and post method
HTML hyperlinks send GETs.
To POST, you need to use a form.
or some Javascript
You can also use Ajax.ActionLink where you can specify POST or GET
#Ajax.ActionLink("Create New", "Edit", "Subtask",
new AjaxOptions{ HttpMethod="Post"})
Related
How to create token "#!" in asp.net mvc?
How to create html snapshot?
I have read google document, They talk create "Indicate to the crawler that your site supports the AJAX crawling scheme" by www.example.com/ajax.html#key=value to change www.example.com/ajax.html#!key=value.
But in asp.net mvc 4 I can't how to create "#!" because when i use #Ajax.ActionLink("link text", "controller", new { attribute router here },new AjaxOptions{ HttpMethod="GET", InsertionMode= InsertionMode.Replace, UpdateTargetId ="id to add function of ajax"}). So it gernater "action/?key=valuer" not like i expected "action/#!key=value"
So somebody help me. I want to google crawble link when ajax function do when i click a text and ajax function excute
what is html snapshot, is this create after when i excute ajax function( click text and ajax function do gernater hmtl to UpdattagetId(I code in asp mvc). So i can dont change any thing with existing i haved code: Ajax.actionlink(...) and gernerater html to UpdatetargetId)
Does anyone know what I need to get the ajax.beginform to work in my MVC4 project? I updated the jQuery library to version 2 and I have included the jquery.validate.js and jquery.validate.unobtrusive.js but the form is still posting to the new page rather than just updating the UpdateTargetId element
I have had a google and a lot of people seem to be having problems with a script called Microsoft.jQuery.Unobtrusive.Ajax but this isn't in my project. Do I need to install this, and if so do I then need to do a find and replace on live so that it uses on instead?
This is the form code:
#using (Ajax.BeginForm("AddImage", "Quote", FormMethod.Post, new AjaxOptions { UpdateTargetId = "Files" }, new { enctype = "multipart/form-data" }))
{
}
This posts to the quote controller addimage action and all that does is write out a string to the screen (which should appear in the Files div) but instead of doing an ajax call it is actually going to the Quote/AddImage page
All I had to do in the end was download the latest jquery.unobtrusive-ajax.js through nuget. This has been updated so it works with jquery 2
First, you're missing InsertionMode in your AjaxOptions.
Second, it seems you're trying to upload files using Ajax form? You won't be able to. Please see this post, for example.
Finally, Ajax.BeginForm is using jQuery.live() function, which has been removed as of jQuery version 1.9. See this question for more info.
You should install jQuery Migrate Plugin which will restore deprecated features. This will at least restore your Ajax form functionality. Alas, it won't help you upload files through Ajax. But that's a different topic.
I am developing a mobile website in MVC4 (using Razor view Engine).
The issue I am facing is that When I navigate to different View using RedirectToAction() method, the new view is served but the URL remains the same in the browser.
I searched about it and found that If I disable the AJAX on my page (by setting attribute [data-ajax=false]) then It start working fine(i.e. correct URL is displayed). But Ajax stops working.
But my problem is that I can not disable AJAX for mobile website & I need to display correct URL for each page.
EDIT:
[HttpPost]
public ActionResult Search(string btnSelection)
{
//Some code here...
//Then redirect to another View using following command:
return RedirectToAction("SelectTask", "Task");
}
But to achieve proper URL display in MVC4 mobile, I have to set following attribute in View:
#using (Html.BeginForm("Search", "Task", FormMethod.Post, new { data_ajax = false }))
But this stops the AJAX. Any ideas how to fix this using AJAX?
Please help if you can asap.
Thanks.
Ajax is not for navigating. You must submit form if you have data to save or use a link (e.g. #Html.ActionLink("Home", "Index", "Home")) to redirect to the other view.
I am trying to use the MVCPaging for asp.net mvc 3, which can be found here but I cannot make it works. I follow this tutorial step by step, but when I click on the link pages, which supposed to load into a div as ajax, it opens me another new pages,
My code from the view is:
#Html.Pager(1, 1, 2, new AjaxOptions { UpdateTargetId = "gridcontainer"}).Options(o => o.Action("AjaxPage"))
Which calls the action ok, it returns a partial, but the partial page is open into another new page instead of refreshing a div on my actual page
This problem gets me crazy, does any one using this nuget package and knows where the problem may be coming from ?
Otherwise, can you advice me a link / tutorial for asp.net mvc 3 for ajax paging ?
I had this problem and adding a reference to jquery.unobtrusive-ajax.js in your _Layout.cshtml view solved it for me.
I have Ajax.ActionLink that POSTS to a method on a controller and passes an Id.
It definitely posts as I have decorated the method with: [HttpPost].
The url is displaying the Id value.
Is this correct, as I would have thought POSTing would hide the Id from the url.
I'm wondering if this is default functionality of MVC3 or whether I need to change my routevalues?
Thanks
Decorating the controller method is not enough, and doesn't look to be the problem in this case.
If the id is showing as part of the URL, the request is likely a GET rather than a POST.
You can specify the request type in the Ajax.ActionLink. Make sure you indicate that it should be a POST.
Do this using AJAX Options.