1

How do I show my data I did Get through the Json and want to show a view?

My code:

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();

My Button Code:

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

My script code:

         $.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("~");
                },

What i make wrong? Please help me... I really need this make

  • I suggest you create a [ViewModel](http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc) for your `RegisteredUser` model and then return a view with the corresponding viewmodel: `return View("YourView", registeredUserViewModel)` – actaram Aug 24 '16 at 13:11
  • I already have the view, if i return with view mode, it's ok, he pass the data but don't work if i click in 'ok' btn. – Thiago Schettini Mari Aug 24 '16 at 13:15
  • What are you doing there, do you get the `JsonToReturn` in the async ajax request? Or it as an Action which should render the view with that data? – DontVoteMeDown Aug 24 '16 at 13:19
  • I start with an action which then processes the data , I have a normal page with a user already created , then have the ' Profile ' page on which you would like to show the information that is shown above and in the end I would like to edit the signature and sav – Thiago Schettini Mari Aug 24 '16 at 13:37

1 Answers1

-1

you need to inject the data returned to L

success: function (Data) 

read injecting data into html page using javascript and json object

i know i hate this site too

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

Liam
  • 27,717
  • 28
  • 128
  • 190
Emil
  • 281
  • 1
  • 2
  • 11