I'm trying to use the ASP.NET MVC Ajax.BeginForm helper, but I don't want to use the existing content insertion options when the call ends. Instead, I want to use a custom JavaScript function as a callback.
This works, but the result I want should be returned as JSON. Unfortunately, the structure simply processes the data as a string. Below is the customer code. The server code simply returns a JsonResult with one field, UppercaseName.
<script type='text/javascript'> function onTestComplete(content) { var result = content.get_data(); alert(result.UppercaseName); } </script> <% using (Ajax.BeginForm("JsonTest", new AjaxOptions() {OnComplete = "onTestComplete" })) { %> <%= Html.TextBox("name") %><br /> <input type="submit" /> <%} %>
Instead of showing the result in uppercase, undefined is displayed instead. content.get_data () seems to contain JSON, but only in string form. How do I convert this to an object?
It all seems a bit confusing. Is there a better way to get the received content using Ajax.BeginForm? If this is complicated, I can completely skip Ajax.BeginForm and just use the jQuery form library.
javascript asp.net-mvc asp.net-ajax
Brian Vallelunga Nov 20 '08 at 3:25 2008-11-20 03:25
source share