Ajax.BeginForm in ASP.MVC2 - asp.net-mvc

I'd like to capture submit action from "Ajax.BeginForm (...)" and asynchronously fetch some data from controler and put it into some div...
How can i do it?
I've tried
Ajax.BeginForm(..., new AjaxOption( UpdateTriggerId = "", ) but as i noticed it is used for online checking form or something like this...
How can i disable reload whole page while pressing "submit" ?? Mayby i have add something to controler?
Btw. What is better to use with forms (in AJAX context)? Pure Jquery or those Ajax.BeginForm?

You should be able to achieve what you need using Ajax.BeginForm and with a partial view...
http://davidhayden.com/blog/dave/archive/2009/05/19/ASPNETMVCAjaxBeginForm.aspx

Related

Grails form submit without changing the view

I want to call an action (it does some filtering and send mails) from my GSP but I want to stay on that GSP. How to acoplish this? Thanks.
You have to use Ajax to submit your form.
Use the formRemote tag to achieve an Ajax submit.
Alternatively you could build it on your own by hooking into the onSubmit event of you form.
If you want to do this with a form, you can take a look on 'submitToRemote' tag: submitToRemote
but if you want to do it with a hyperlink... take a look on 'remoteLink' tag: remoteLink

What is a good way to implement a data report grid on my MVC3 page

Before I start work I would like to get some ideas. What I have is an MVC3 page that I currently use to display rows of data. There are many rows so I would like to filter them. Ideally at the top of my page I would like to have a select drop down box and a refresh button with rows of data appearing below when the refresh button is clicked.
I can imagine doing this with Ajax and then having the data from my controller populate new HTML text between a DIV.
Does this sound like the best approach? I am not looking for a person to write code for me. Just want to be sure my solution sounds like a good way to go.
thank you
i recommend this approach:
http://geekswithblogs.net/michelotti/archive/2008/06/28/mvc-json---jsonresult-and-jquery.aspx
You can 'enchance' it with AJAX of course, but do not forget about users with disabled javascript. Make it work without client scripting, then enchance it, when its working.
I also think that you can simply create controller action, that is accepting parameters like pageNumber and amountOfItems. Then in your controls at page, you can just change values (number of page etc..) and use them in call for your controller action at form submit.

How can i return a form using ajax into a view ASP.Net MVC

i just started building a small test app to help me learn MVC. i have a view that displays user comments. Under each comment i would like to have a reply action link. Clicking on the link should return a small form for adding a comment directly above the reply link.
What is the general approach for this? I'm imaging the form would be a partial view that i can somehow return using the reply link. Thanks for any help!
Using jQuery to retrieve and post the forms in partial views is how I would do it.
Just return partial view to be loaded by jQuery load:
$('#comment').load('/MyController/ActionReturnsPartial');
You should not have to retrieve anything from the server if the user is not providing any extra information along with the retrieval.
Instead of retrieving the form when the user clicks, just let the page render a form below each comment. Put the form in a div with style="display: none;". Then, when the user cliks the link, use jQuery to show the form. Something like
$('.commentlink').click(function(){
$(this).closest('div').find('.formdiv').show();
});
You may also be able to use jQuery's .toggle() method.

ASP.Net MVC run JavaScript in PartialView when loaded using Ajax.ActionLink

I've got a question regarding ASP.Net MVC.
I'm using an Ajax.ActionLink to load a PartialView.
In this partial view is a javascript function I'd like to get called.
However I can't figure out how to make this happen.
I've tried using AjaxOptions { OnSuccess="functionInPartialView" } when I set the Ajax.ActionLink but for some reason it can't see the Javascript.
EDIT: The PartialView is a mix of JavaScript and Html
I would suggest to use jQuery ($.get/$.ajax). It evaluates the $(function(){}) when you load the partial, so your scripts there fire. And I personally find jQuery easier and cleaner to use.
Add the javascript code in the view that will contain the parcialview, and next use the ajaxOptions { OnSuccess="functionInView" } when you set the Ajax.ActionLink.
If it's only javascript in your partial view, then you should be using a JavaScript Action result, as in this post
Otherwise, the issue is that ajax merely loading content into a div doesn't mean that it executes. In your ajax callback, you need to find the javascript content and eval it, so that your page is aware of the function definition.
I know that's a high level description, but I don't have any samples of doing this. If you post some of the code, maybe someone can suggest a cleaner way of doing this so that you have better access to the script.
You can try Multipartials , you can use them to update multiple views and even run scripts from partials, im not sure about the exact specifics as its been a while, but you can have a look at it and see if it can accomplish what you are looking for

Redirect from within an Ajax form post

I have an action method that depending on some conditions needs to return a partial view via ajax, or redirect to another Controller/Action. The correct view is returned but it is placing it in the Ajax forms UpdateTargetId rather than redirecting to a completely new page. Anyone have any idea how I can accomplish this?
I think I would refactor this to use jQuery rather than MVC Ajax. jQuery will give you a lot more control over what you can do with the result that you get back. If that's not an option, you might want to look at the OnComplete callback and see what data you get passed to it and see if there is a way get the url that you want to be redirected to from it.
Also, I seem to remember that if you return a JavaScriptResult it will execute it regardless of how the AJAX was invoked. You might want to try something like:
return JavaScript( "window.top.location.href ='" + Url.Action( "Action" ) + "';" );
May be this link could help to solve your problem, and insert your javascript to change current page to other controller, for example
window.location = 'controller/action';

Resources