Sunday, August 15, 2010

Ajax helper in .NET MVC 2 and form problem

Recently I've been working with some legacy code with a weird design. Currently we are migrating some parts of a solution from ASP.NET to MVC 2. The problem is that entire content of the page is inside one giant 'form' tag that is in a master page, and there is no 'form' nesting in html standard. I was hoping to use Ajax.Form helper from MVC 2 to solve this issue - I mean, I hoped that it will behave as a some other kind of container then 'form' and submit information via AJAX requests. For example in a 'div' tag. Unfortunately for me Ajax.BeginForm generates a 'form' container, like:

<form onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });" onclick="Sys.Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));" method="post" action="/Ajax/Foo">


Jet again I have to write my own JavaScript code to handle some action inside 'div' contaier.

I hope that soon I will receive a green light to refactor the master page and remove the 'form' tag from it. It is a bad place to place it.

No comments: