rafanoronha.speaking()

software development stuff

Archive for the ‘ASP NET MVC’ tag

Ajax post requests in Asp Net Mvc

without comments

I really enjoy that Asp Net Mvc gave me back the control of my Html.
Now I can easily work on nice javascript user interactions and integrate it with server side code in a very clean approach.

So let’s see how I am doing Ajax post requests in Asp Net Mvc, on the top of jQuery library.

At the master page I have a hidden input called ErrorAction, so my client-side code will know what url should be called when an error occurs in Ajax requests.

Still at the master page, we tell jQuery that by default this Error Action should be invoked when something bad occurs while executing a request.

Finally, we can work on the post requests in a safe way. And that is really easy.
Here is how it works.

<% =Html.Hidden("ErrorAction", Url.Action("Index", "Error"))%>

<script type="text/javascript">
        jQuery.ajaxSetup({
            error: function(XMLHttpRequest, textStatus, errorThrown)
                        { window.location = $("ErrorAction").value; }
        });
</script>

<% =Html.ActionLink("Update Permissions", "Permissions", null ,
        new { id = "updatePermissions",
              style = "visibility: hidden;",
              onclick = @"jQuery.ajax(
                        {
                            url:this.href,
                            type:'POST',
                            data:
                            {
                                scrumMasters:permissionsInRole('scrumMasters'),
                                productOwners:permissionsInRole('productOwners'),
                                teamMembers:permissionsInRole('teamMembers'),
                                chickens:permissionsInRole('chickens')
                            },
                            complete: permissionsUpdated
                         }); return false;"
        })%>

Written by rafanoronha

May 28th, 2009 at 3:13 am

Posted in Sem categoria

Tagged with ,

(Portuguese) Asp Net MVC: T4 te dá asas e produtividade

without comments

Sorry, this entry is only available in Portuguese.

Written by rafanoronha

April 10th, 2009 at 5:13 pm

Posted in Sem categoria

Tagged with ,

(Portuguese) ASP NET MVC 1.0 lançado oficialmente

with 2 comments

Sorry, this entry is only available in Portuguese.

Written by rafanoronha

March 20th, 2009 at 12:22 am

Posted in Sem categoria

Tagged with