2016-08-24 8 views
1

データを表示するにはをJsonで入手し、ビューを表示したいですか?View()でJson Dataを返す方法は?

マイコード:

RegisteredUser U = RegisteredUser.FindByAPI(Id); 

       var JsonToReturn = new 
       { 
        Name = U.Name, 
        Departamento = U.Department, 
        Email = U.Email, 
        signature = U.Signature 
       }; 
       //return Json(JsonToReturn, JsonRequestBehavior.AllowGet); 
       return View(); 

マイボタンのコード:

<a class="btn btn-success" role="submit-ticket"> 
        <span class="glyphicon glyphicon-send" aria-hidden="true"></span> 
        Criar 
       </a> 

私のスクリプトコード:

  $.ajax({ 
       url: '@Url.Content("~")/Perfil/Index', 
       method: 'POST', 
       processData: false, 
       contentType: false, 
       data: Data, 
       beforeSend: function() { 
        SubmitButton.children('span').removeClass('glyphicon-send').addClass('glyphicon-cog').addClass('spinning'); 
        SubmitButton.attr('disabled', ''); 
        CancelButton.attr('disabled', ''); 
       }, 
       success: function (Data) { 
        SubmitButton.children('span').removeClass('glyphicon-cog').addClass('glyphicon-ok'); 
        window.location.href = '@Url.Content("~"); 
       }, 

私が間違って作りますか?私を助けてください...私は本当にあなたがデータを挿入する必要があり、これは

+0

私はあなたが作成することをおすすめ[ViewModelに](http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc)返されたView( "YourView"、registeredUserViewModel) ' – TheWanderingMind

+0

私はすでにビューを持っていますが、ビューモードで返されてもOKですが、データは渡しても動作しません私が 'ok' btnをクリックすると。 –

+0

ここで何をしていますか?非同期のajaxリクエストで 'JsonToReturn'を取得しますか?または、そのデータを表示するアクションとして、それを使用しますか? – DontVoteMeDown

答えて

-1

を作る必要があるL

に戻っ
success: function (Data) 

は、私が嫌い知っているJavaScriptを使用してHTMLページにデータを注入読み込み、JSONオブジェクト

あなた `Registeのため、このサイトあまりに

http://www.w3schools.com/json/json_files.asp

+0

私は 'w3schools'サイトのようにheheありがとう –

関連する問題