ASP.NET MVC jQuery mobile like pages mechanism - ajax

To give a more appish experience to my asp.net mvc application, I would like to make the links to other pages (actions in mvc) be loaded using ajax (displaying a loading sign while the request is being processed). I have been quite successful doing this with jQuery Mobile but for the project that I am doing now I prefer not to use it. In part this is because as soon as loading jQuery Mobile css the previous look of the site is disrupted.
Is there a similar page mechanism in asp.net? It would be even better if features such as transitions and pre-rendering of pages would be available too, as jQuery Mobile does.
An example of what I try to achieve
I have a controller like this:
public ActionResult List()
{
return View();
}
public ActionResult Dashboard()
{
return View();
}
Then on the dashboard view a link:
LIST
Clicking the link would request the list page from the server and start a slide effect to transition from one page to the other.
Thanks for your ideas and knowledge on that!

Related

Equivalent to RedirectToPage in MVC?

I have a ASP.NET Core 2.0 web application with a mix of Razor Pages and MVC. When I do a POST to the page, I often want to redirect the user back to the same page, but with a GET request.
In ASP.NET Core 2.0 Razor Pages, I typically do it like this:
public async Task<IActionResult> OnPostView(...)
{
// Update based on POST data
...
return RedirectToPage(); // Redirect back to GET
}
What is the equivalent to this in a MVC controller?
The equivalent method is:
return RedirectToAction();
See the source for more information.

ASP.NET MVC: Is it possible to browse all public functions inside a contoller, like in ASMX

If you open an ASMX file in a browser, it shows you a nice summary of all of its functions.
Is it possible to do the same for all public functions in ASP.NET MVC controller ?
No, not from a browser.
The whole point of having a controller is to control what is displayed in the view. The controller should not present itself to the browser. By it's very nature a controller is designed to present something else to the browser, namely the view:
You could, however use a tool like Glimpse to get a peak at those public functions.

How to handle jQuery event on an ASP.net MVC Ajax loaded page?

i've got an issue.
I'm a newbie in the world of jQuery Mobile, and with the ASP.Net MVC part I'm a little bit lost.
Here is my problem: In my mobile web site I want to change the navbar (that I use more like an appbar) buttons whereas I am on an Edit Page, or Home, etc....
So those pages (Edit, Show) are loaded in ajax, and on these pages I'm trying to fire an event like :
$(document).ready(function(){
alert("Hello !");
});
But after some researchs, i found that in JQM with Ajax, events doesn't work that way, but more like this :
$(document).bind('pageinit', function(){
alert("Hello !");
});
But this don't work for me (every page change the event is trigerred), maybe because in ASP.Net MVC Mobile we have only one data-role="page" and the rest of the content are loaded in ajax in the data-role="content", so I really don't know how I can fire an event when my "Ajax Loaded Kind of Page" is loaded ?
I had tried to live/bind on the listview of one of these pages but that does not work either :
$("[data-role='listview']").live('pageinit', function () {
alert("hello");
});
To be more precise about what i'm trying to do :
In ASP.Net MVC, my layout (who his common to all my pages) has a div with a data-role="page"attribute. This data-role is unique to my all app, and need to deal with it.
But the fact is, when I load an other ASP.Net MVC Page in my code :
<div data-role="page" >
<div data-role="content"> Here my ASP.Net MVC Page</div>
</div>
I cannot use the $(document).bind('pagenit') because i don' load a page (data-role=page) but just a part of a data-role="content".
If you have any idea I will be glad to hear (more read) it, thanks in advance and sorry if my english is not really "understandable".
Jquery Mobile gets the view through the AJAX and displays it. Due to this, the general events miss out since it is an AJAX call.
The best option is to disable Ajax for every form, you need to mention on each redirection call as well
data_ajax = "false"
Once it becomes a regular call, all Jquery events work normally!

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.

ASP.NET MVC3 - Action without reload site

I have MVC3 app with form for edit data. This for include only dropdownlist.
It is any posibility to execute Controller method (HttpPost) without reload?
If not - how Can I return current site (because I have the same form in different sites).
Yes, try XmlHttpRequest better known as AJAX to execute controllers. It's like sending a request from the browser to the server on a background thread which won't cause a page reload.
have a read of these blogs:
http://www.nikhilk.net/Ajax-MVC.aspx
http://dotnetslackers.com/articles/aspnet/ASP-NET-MVC-2-0-and-AJAX-Part-1.aspx
If you can't use ajax, to get back to the same page you can redirect the user back to the referrer url:
public ActionResult Submit()
{
// do something
return Redirect(Request.UrlReferrer.ToString());
}

Resources