views:

1313

answers:

3

Hello together, My first Question on Stackoverflow, I am new on the .NET MVC pattern and tried to call a Action using AJAX.BeginForm Helper Class in my Controller I return seralized JSON using return JSON();

In my view I Added a Scrip witch should consume the returnes JSON.

   function ResultSet(request) {

   var json = content.get_response().get_object();
   var result = eval(json);

   if (result.Successfull) {
       alert("Success!");
   }
   else {
       alert("else");
       }
   }

But instead if I am returned the Browser Shows me a Save Dialog to Save the JSON file.

Why?

Thanks in advance Johannes

A: 

try setting content type of response to application/json as follows:

Response.ContentType = "application/json";
TheVillageIdiot
That's redundant. Return Json() already does it.
Craig Stuntz
+1  A: 

Hi Johannes! I've had a similar problem, try making sure you added the references to the microsoft ajax libraries:

<script src="/Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>

also. your ResultSet() method takes a variable named "request" as parameter, I think it should be called "content", like this?

<script type="text/javascript">
    function ResultSet(content) {
        var json = content.get_response().get_object();

        var result = eval(json);
        if (result.Successfull) {
            alert("Success!");
        }
        else {
            alert("else");
        }
    }    
</script>
Johan Danforth
A: 

You've forgotten to reference jQuery. Put this inside the head of your html:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; 
Konstantin Spirin