How to display a fully formed HTML page as an MVC view?












0














MVC/ASP.NET/C#/html/javascript newbie question:



I'm trying to move some legacy software into an MVC solution. I have an MVC controller ViewResult method that makes an API call to the legacy system and returns a string which is a fully formed HTML page (including the HTML start and end tags). Some time in the future, I'll rewrite the logic as an MVC view, but for right now I need to just display that page (preferably in a new tab).



I've tried this in the controller:



return View((object)calendar);  


(where "calendar" is the string containing the HTML document)



In my view I have



  @model string  
@{ Layout = null; }
@Model


But that didn't work.

Any ideas?










share|improve this question





























    0














    MVC/ASP.NET/C#/html/javascript newbie question:



    I'm trying to move some legacy software into an MVC solution. I have an MVC controller ViewResult method that makes an API call to the legacy system and returns a string which is a fully formed HTML page (including the HTML start and end tags). Some time in the future, I'll rewrite the logic as an MVC view, but for right now I need to just display that page (preferably in a new tab).



    I've tried this in the controller:



    return View((object)calendar);  


    (where "calendar" is the string containing the HTML document)



    In my view I have



      @model string  
    @{ Layout = null; }
    @Model


    But that didn't work.

    Any ideas?










    share|improve this question



























      0












      0








      0







      MVC/ASP.NET/C#/html/javascript newbie question:



      I'm trying to move some legacy software into an MVC solution. I have an MVC controller ViewResult method that makes an API call to the legacy system and returns a string which is a fully formed HTML page (including the HTML start and end tags). Some time in the future, I'll rewrite the logic as an MVC view, but for right now I need to just display that page (preferably in a new tab).



      I've tried this in the controller:



      return View((object)calendar);  


      (where "calendar" is the string containing the HTML document)



      In my view I have



        @model string  
      @{ Layout = null; }
      @Model


      But that didn't work.

      Any ideas?










      share|improve this question















      MVC/ASP.NET/C#/html/javascript newbie question:



      I'm trying to move some legacy software into an MVC solution. I have an MVC controller ViewResult method that makes an API call to the legacy system and returns a string which is a fully formed HTML page (including the HTML start and end tags). Some time in the future, I'll rewrite the logic as an MVC view, but for right now I need to just display that page (preferably in a new tab).



      I've tried this in the controller:



      return View((object)calendar);  


      (where "calendar" is the string containing the HTML document)



      In my view I have



        @model string  
      @{ Layout = null; }
      @Model


      But that didn't work.

      Any ideas?







      model-view-controller view model






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 4:33

























      asked Nov 21 '18 at 16:42









      Gustaaf Vandermeeren

      33




      33
























          3 Answers
          3






          active

          oldest

          votes


















          1














          Model binding is binding the object of your model class.



          For example, ([Solution].[Models].[Model class]),



          @model PassDatainMVC.Models.Record


          To pass the data from controller to view,



          Approach 1: ViewBag



          Controller:



          string data = "testing";
          ViewBag.see = data;
          return View();


          View:



          @using PassDatainMVC.Models
          @ViewBag.see


          Or:



          Approach 2: Model binding



          Controller (Class):



          public string recordProperty;


          View:



          @model PassDatainMVC.Models.Record
          @Model.recordProperty


          While you have to set the property under the model class in the data field for the second approach.



          Ref. https://www.c-sharpcorner.com/article/asp-net-mvc-passing-data-from-controller-to-view/






          share|improve this answer























          • Thank you Wing, but both you and Reha are missing the point. I'm not a total newbie to MVC. I have successfully built a view views and used both ViewBag and models to pass data into the .cshtml file. It all works fine when the data is just a simple string. But when, as in my case, the data is a complete HTML page specification (ie, the string starts with an html open tag and ends with an html close tag, with an entire html specification (over 5000 characters) inbetween) then everything I try just ends up displaying the html code instead of the html page itself.
            – Gustaaf Vandermeeren
            Nov 23 '18 at 16:56










          • This may be helpful: stackoverflow.com/questions/22781548/…
            – Wing Kui Tsoi
            Nov 23 '18 at 17:11












          • Thank you Wing. Your reference to stackoverflow.com/questions/22781548/… solved the problem. I now use Html.Raw in my view. The entire view now consists of just two lines of code: @{Layout = null;} @Html.Raw(ViewBag.calendar ) ;
            – Gustaaf Vandermeeren
            Nov 23 '18 at 21:47












          • You're welcome :)
            – Wing Kui Tsoi
            Nov 23 '18 at 22:03



















          0














          If you want to just one data you can use a ViewBag. This is simple.



          Also you want to send with model. You should use this code.



          Class



           public class Calendar
          {
          public string CalendarName { get; set; }
          }


          Controller



          Calendar newModel = new Calendar();
          newModel.CalendarName = "test name...";
          return View(newModel);


          View



           @model ModelNamespace.Calendar

          <h1> @Model.CalendarName </h1>





          share|improve this answer





















          • Thanks! But unfortunately neither of those worked.
            – Gustaaf Vandermeeren
            Nov 23 '18 at 6:11





















          0














          Thanks Reha! But unfortunately neither of your suggestions did the trick.

          For your first suggestion I used ViewBag. In the controller I replaced



          return View((object)calendar);


          to



          ViewBag.calendar = calendar;
          return View();


          And replaced the view with just



          @{ Layout = null; }
          @ViewBag.calendar


          The result was that the user is left looking at the actual HTML code instead of what the HTML code is supposed to render.



          For your 2nd suggestion, I did exactly as you suggested (except I changed
          Model.CalendarName = "test name...";
          to
          Model.CalendarName = calendar;
          The result is the same, the user is left looking at the HTML code.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416797%2fhow-to-display-a-fully-formed-html-page-as-an-mvc-view%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Model binding is binding the object of your model class.



            For example, ([Solution].[Models].[Model class]),



            @model PassDatainMVC.Models.Record


            To pass the data from controller to view,



            Approach 1: ViewBag



            Controller:



            string data = "testing";
            ViewBag.see = data;
            return View();


            View:



            @using PassDatainMVC.Models
            @ViewBag.see


            Or:



            Approach 2: Model binding



            Controller (Class):



            public string recordProperty;


            View:



            @model PassDatainMVC.Models.Record
            @Model.recordProperty


            While you have to set the property under the model class in the data field for the second approach.



            Ref. https://www.c-sharpcorner.com/article/asp-net-mvc-passing-data-from-controller-to-view/






            share|improve this answer























            • Thank you Wing, but both you and Reha are missing the point. I'm not a total newbie to MVC. I have successfully built a view views and used both ViewBag and models to pass data into the .cshtml file. It all works fine when the data is just a simple string. But when, as in my case, the data is a complete HTML page specification (ie, the string starts with an html open tag and ends with an html close tag, with an entire html specification (over 5000 characters) inbetween) then everything I try just ends up displaying the html code instead of the html page itself.
              – Gustaaf Vandermeeren
              Nov 23 '18 at 16:56










            • This may be helpful: stackoverflow.com/questions/22781548/…
              – Wing Kui Tsoi
              Nov 23 '18 at 17:11












            • Thank you Wing. Your reference to stackoverflow.com/questions/22781548/… solved the problem. I now use Html.Raw in my view. The entire view now consists of just two lines of code: @{Layout = null;} @Html.Raw(ViewBag.calendar ) ;
              – Gustaaf Vandermeeren
              Nov 23 '18 at 21:47












            • You're welcome :)
              – Wing Kui Tsoi
              Nov 23 '18 at 22:03
















            1














            Model binding is binding the object of your model class.



            For example, ([Solution].[Models].[Model class]),



            @model PassDatainMVC.Models.Record


            To pass the data from controller to view,



            Approach 1: ViewBag



            Controller:



            string data = "testing";
            ViewBag.see = data;
            return View();


            View:



            @using PassDatainMVC.Models
            @ViewBag.see


            Or:



            Approach 2: Model binding



            Controller (Class):



            public string recordProperty;


            View:



            @model PassDatainMVC.Models.Record
            @Model.recordProperty


            While you have to set the property under the model class in the data field for the second approach.



            Ref. https://www.c-sharpcorner.com/article/asp-net-mvc-passing-data-from-controller-to-view/






            share|improve this answer























            • Thank you Wing, but both you and Reha are missing the point. I'm not a total newbie to MVC. I have successfully built a view views and used both ViewBag and models to pass data into the .cshtml file. It all works fine when the data is just a simple string. But when, as in my case, the data is a complete HTML page specification (ie, the string starts with an html open tag and ends with an html close tag, with an entire html specification (over 5000 characters) inbetween) then everything I try just ends up displaying the html code instead of the html page itself.
              – Gustaaf Vandermeeren
              Nov 23 '18 at 16:56










            • This may be helpful: stackoverflow.com/questions/22781548/…
              – Wing Kui Tsoi
              Nov 23 '18 at 17:11












            • Thank you Wing. Your reference to stackoverflow.com/questions/22781548/… solved the problem. I now use Html.Raw in my view. The entire view now consists of just two lines of code: @{Layout = null;} @Html.Raw(ViewBag.calendar ) ;
              – Gustaaf Vandermeeren
              Nov 23 '18 at 21:47












            • You're welcome :)
              – Wing Kui Tsoi
              Nov 23 '18 at 22:03














            1












            1








            1






            Model binding is binding the object of your model class.



            For example, ([Solution].[Models].[Model class]),



            @model PassDatainMVC.Models.Record


            To pass the data from controller to view,



            Approach 1: ViewBag



            Controller:



            string data = "testing";
            ViewBag.see = data;
            return View();


            View:



            @using PassDatainMVC.Models
            @ViewBag.see


            Or:



            Approach 2: Model binding



            Controller (Class):



            public string recordProperty;


            View:



            @model PassDatainMVC.Models.Record
            @Model.recordProperty


            While you have to set the property under the model class in the data field for the second approach.



            Ref. https://www.c-sharpcorner.com/article/asp-net-mvc-passing-data-from-controller-to-view/






            share|improve this answer














            Model binding is binding the object of your model class.



            For example, ([Solution].[Models].[Model class]),



            @model PassDatainMVC.Models.Record


            To pass the data from controller to view,



            Approach 1: ViewBag



            Controller:



            string data = "testing";
            ViewBag.see = data;
            return View();


            View:



            @using PassDatainMVC.Models
            @ViewBag.see


            Or:



            Approach 2: Model binding



            Controller (Class):



            public string recordProperty;


            View:



            @model PassDatainMVC.Models.Record
            @Model.recordProperty


            While you have to set the property under the model class in the data field for the second approach.



            Ref. https://www.c-sharpcorner.com/article/asp-net-mvc-passing-data-from-controller-to-view/







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 '18 at 15:55

























            answered Nov 23 '18 at 15:49









            Wing Kui Tsoi

            15111




            15111












            • Thank you Wing, but both you and Reha are missing the point. I'm not a total newbie to MVC. I have successfully built a view views and used both ViewBag and models to pass data into the .cshtml file. It all works fine when the data is just a simple string. But when, as in my case, the data is a complete HTML page specification (ie, the string starts with an html open tag and ends with an html close tag, with an entire html specification (over 5000 characters) inbetween) then everything I try just ends up displaying the html code instead of the html page itself.
              – Gustaaf Vandermeeren
              Nov 23 '18 at 16:56










            • This may be helpful: stackoverflow.com/questions/22781548/…
              – Wing Kui Tsoi
              Nov 23 '18 at 17:11












            • Thank you Wing. Your reference to stackoverflow.com/questions/22781548/… solved the problem. I now use Html.Raw in my view. The entire view now consists of just two lines of code: @{Layout = null;} @Html.Raw(ViewBag.calendar ) ;
              – Gustaaf Vandermeeren
              Nov 23 '18 at 21:47












            • You're welcome :)
              – Wing Kui Tsoi
              Nov 23 '18 at 22:03


















            • Thank you Wing, but both you and Reha are missing the point. I'm not a total newbie to MVC. I have successfully built a view views and used both ViewBag and models to pass data into the .cshtml file. It all works fine when the data is just a simple string. But when, as in my case, the data is a complete HTML page specification (ie, the string starts with an html open tag and ends with an html close tag, with an entire html specification (over 5000 characters) inbetween) then everything I try just ends up displaying the html code instead of the html page itself.
              – Gustaaf Vandermeeren
              Nov 23 '18 at 16:56










            • This may be helpful: stackoverflow.com/questions/22781548/…
              – Wing Kui Tsoi
              Nov 23 '18 at 17:11












            • Thank you Wing. Your reference to stackoverflow.com/questions/22781548/… solved the problem. I now use Html.Raw in my view. The entire view now consists of just two lines of code: @{Layout = null;} @Html.Raw(ViewBag.calendar ) ;
              – Gustaaf Vandermeeren
              Nov 23 '18 at 21:47












            • You're welcome :)
              – Wing Kui Tsoi
              Nov 23 '18 at 22:03
















            Thank you Wing, but both you and Reha are missing the point. I'm not a total newbie to MVC. I have successfully built a view views and used both ViewBag and models to pass data into the .cshtml file. It all works fine when the data is just a simple string. But when, as in my case, the data is a complete HTML page specification (ie, the string starts with an html open tag and ends with an html close tag, with an entire html specification (over 5000 characters) inbetween) then everything I try just ends up displaying the html code instead of the html page itself.
            – Gustaaf Vandermeeren
            Nov 23 '18 at 16:56




            Thank you Wing, but both you and Reha are missing the point. I'm not a total newbie to MVC. I have successfully built a view views and used both ViewBag and models to pass data into the .cshtml file. It all works fine when the data is just a simple string. But when, as in my case, the data is a complete HTML page specification (ie, the string starts with an html open tag and ends with an html close tag, with an entire html specification (over 5000 characters) inbetween) then everything I try just ends up displaying the html code instead of the html page itself.
            – Gustaaf Vandermeeren
            Nov 23 '18 at 16:56












            This may be helpful: stackoverflow.com/questions/22781548/…
            – Wing Kui Tsoi
            Nov 23 '18 at 17:11






            This may be helpful: stackoverflow.com/questions/22781548/…
            – Wing Kui Tsoi
            Nov 23 '18 at 17:11














            Thank you Wing. Your reference to stackoverflow.com/questions/22781548/… solved the problem. I now use Html.Raw in my view. The entire view now consists of just two lines of code: @{Layout = null;} @Html.Raw(ViewBag.calendar ) ;
            – Gustaaf Vandermeeren
            Nov 23 '18 at 21:47






            Thank you Wing. Your reference to stackoverflow.com/questions/22781548/… solved the problem. I now use Html.Raw in my view. The entire view now consists of just two lines of code: @{Layout = null;} @Html.Raw(ViewBag.calendar ) ;
            – Gustaaf Vandermeeren
            Nov 23 '18 at 21:47














            You're welcome :)
            – Wing Kui Tsoi
            Nov 23 '18 at 22:03




            You're welcome :)
            – Wing Kui Tsoi
            Nov 23 '18 at 22:03













            0














            If you want to just one data you can use a ViewBag. This is simple.



            Also you want to send with model. You should use this code.



            Class



             public class Calendar
            {
            public string CalendarName { get; set; }
            }


            Controller



            Calendar newModel = new Calendar();
            newModel.CalendarName = "test name...";
            return View(newModel);


            View



             @model ModelNamespace.Calendar

            <h1> @Model.CalendarName </h1>





            share|improve this answer





















            • Thanks! But unfortunately neither of those worked.
              – Gustaaf Vandermeeren
              Nov 23 '18 at 6:11


















            0














            If you want to just one data you can use a ViewBag. This is simple.



            Also you want to send with model. You should use this code.



            Class



             public class Calendar
            {
            public string CalendarName { get; set; }
            }


            Controller



            Calendar newModel = new Calendar();
            newModel.CalendarName = "test name...";
            return View(newModel);


            View



             @model ModelNamespace.Calendar

            <h1> @Model.CalendarName </h1>





            share|improve this answer





















            • Thanks! But unfortunately neither of those worked.
              – Gustaaf Vandermeeren
              Nov 23 '18 at 6:11
















            0












            0








            0






            If you want to just one data you can use a ViewBag. This is simple.



            Also you want to send with model. You should use this code.



            Class



             public class Calendar
            {
            public string CalendarName { get; set; }
            }


            Controller



            Calendar newModel = new Calendar();
            newModel.CalendarName = "test name...";
            return View(newModel);


            View



             @model ModelNamespace.Calendar

            <h1> @Model.CalendarName </h1>





            share|improve this answer












            If you want to just one data you can use a ViewBag. This is simple.



            Also you want to send with model. You should use this code.



            Class



             public class Calendar
            {
            public string CalendarName { get; set; }
            }


            Controller



            Calendar newModel = new Calendar();
            newModel.CalendarName = "test name...";
            return View(newModel);


            View



             @model ModelNamespace.Calendar

            <h1> @Model.CalendarName </h1>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 14:00









            Reha Bayar

            11




            11












            • Thanks! But unfortunately neither of those worked.
              – Gustaaf Vandermeeren
              Nov 23 '18 at 6:11




















            • Thanks! But unfortunately neither of those worked.
              – Gustaaf Vandermeeren
              Nov 23 '18 at 6:11


















            Thanks! But unfortunately neither of those worked.
            – Gustaaf Vandermeeren
            Nov 23 '18 at 6:11






            Thanks! But unfortunately neither of those worked.
            – Gustaaf Vandermeeren
            Nov 23 '18 at 6:11













            0














            Thanks Reha! But unfortunately neither of your suggestions did the trick.

            For your first suggestion I used ViewBag. In the controller I replaced



            return View((object)calendar);


            to



            ViewBag.calendar = calendar;
            return View();


            And replaced the view with just



            @{ Layout = null; }
            @ViewBag.calendar


            The result was that the user is left looking at the actual HTML code instead of what the HTML code is supposed to render.



            For your 2nd suggestion, I did exactly as you suggested (except I changed
            Model.CalendarName = "test name...";
            to
            Model.CalendarName = calendar;
            The result is the same, the user is left looking at the HTML code.






            share|improve this answer


























              0














              Thanks Reha! But unfortunately neither of your suggestions did the trick.

              For your first suggestion I used ViewBag. In the controller I replaced



              return View((object)calendar);


              to



              ViewBag.calendar = calendar;
              return View();


              And replaced the view with just



              @{ Layout = null; }
              @ViewBag.calendar


              The result was that the user is left looking at the actual HTML code instead of what the HTML code is supposed to render.



              For your 2nd suggestion, I did exactly as you suggested (except I changed
              Model.CalendarName = "test name...";
              to
              Model.CalendarName = calendar;
              The result is the same, the user is left looking at the HTML code.






              share|improve this answer
























                0












                0








                0






                Thanks Reha! But unfortunately neither of your suggestions did the trick.

                For your first suggestion I used ViewBag. In the controller I replaced



                return View((object)calendar);


                to



                ViewBag.calendar = calendar;
                return View();


                And replaced the view with just



                @{ Layout = null; }
                @ViewBag.calendar


                The result was that the user is left looking at the actual HTML code instead of what the HTML code is supposed to render.



                For your 2nd suggestion, I did exactly as you suggested (except I changed
                Model.CalendarName = "test name...";
                to
                Model.CalendarName = calendar;
                The result is the same, the user is left looking at the HTML code.






                share|improve this answer












                Thanks Reha! But unfortunately neither of your suggestions did the trick.

                For your first suggestion I used ViewBag. In the controller I replaced



                return View((object)calendar);


                to



                ViewBag.calendar = calendar;
                return View();


                And replaced the view with just



                @{ Layout = null; }
                @ViewBag.calendar


                The result was that the user is left looking at the actual HTML code instead of what the HTML code is supposed to render.



                For your 2nd suggestion, I did exactly as you suggested (except I changed
                Model.CalendarName = "test name...";
                to
                Model.CalendarName = calendar;
                The result is the same, the user is left looking at the HTML code.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 6:26









                Gustaaf Vandermeeren

                33




                33






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416797%2fhow-to-display-a-fully-formed-html-page-as-an-mvc-view%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'