How to create ajax crawable in asp.net - ajax

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)

Related

MVC4 Ajax jQuery 2

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.

URL issue in MVC4 Mobile website (Razor View Engine) with AJAX

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.

.net MVC 3.0 file upload with progress bar

I saw there are similar question to this. But I couldn't find an answer. That's why I am posting this again. Sorry!!
I want to build a file uploader with percentage bar with in it using .net mvc 3.0
There are some jquery plugins. But they need html 5 support. I am trying to build it without html 5 support.
Currently what I do is upload files with Ajax support. When file is uploaded by user I make an ajax request and display loading.gif until requested completed. So it is a pretty strait forward code for simple image uploads.
Now I am trying to upload videos and send it to Vimeo through their REST APIs.
I could do the same thing. But since files are large I want to do it in a nice way.
My code is something like this
View
#using (Ajax.BeginForm("Upload", "Home", new AjaxOptions
{
UpdateTargetId = "form1",
InsertionMode = InsertionMode.Replace,
OnBegin = "ajaxValidate",
OnSuccess = "getGbPostSuccess",
OnFailure = "showFaliure"
}))
//.......
//rest of the form
}
Controller
public ActionResult Upload()
{
//Read file
//Post file to Vimeo (this is the part that take time to upload)
//get uploaded video content
return PartialView("xxxxx", Model); // return uploaded Video
}
I display a loading.gif using a small piece of javascript while this process happening. This code is working absolutely fine. As I mention before I want to make it more user friendly by putting a percentage progress bar.
Hope my question is clear.
Please help me...
Thanks in advance
But they need html 5 support.
Not necessary. For example the blueimp file upload plugin tests browser capabilities and could use the jQuery iframe transport if the browser doesn't support HTML5 XHR2. Here are more details about browser support.
Uploadify is another example which uses Flash if the browser doesn't suport XHR2.
Plupload is yet another very powerful plugin which supports a multitude of equivalents if the browser doesn't support XHR2.
So just pick a plugin, read the documentation, integrate it in your ASP.NET MVC 3 application and have fun.

mvcPaging documentation - Mvc pagination advice

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.

MVC3 Html.ActionLink Post

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"})

Resources