2

We need to open a Chart.cshtml page as a modal popup (gray parent window) in our application in center of a parent screen with some values as a input of popup. On popup closing we return some values to parent screen.

Chart.cshtml directory is Views => Home => Chart.cshtml of my MVC application.

Please help me with a sample code. Its really very helpful for me.

Thanks,

Sufyan

Abu Sufyan
  • 197
  • 1
  • 2
  • 14
  • You should use Partial View for this purpose.. Convert Chart.cshtml to Partial view and add it into the modal popup's body in Home.cshtml try to google first, try something yourself and then ask here.. – Sachin Feb 02 '15 at 13:09

2 Answers2

0

MVC Return Partial View as JSON Check this post. You could render partial view from Json using ajax.

Create Action which would return your partial view as Json. When you get response from ajax call (your Partial view as Json), you could insert it in place where you want in parent view.

Community
  • 1
  • 1
demo
  • 6,038
  • 19
  • 75
  • 149
0

Try this:

Have one div and set it contents to action which returns your view cshtml as ViewResult.

Use jQuery ui dialog to show it as popup

HTML

 <div id='divHtml'/>

javascript

    $(document).ready(function()
{
                 $("#divHtml").load("Home/Chart",
                      function()
            {
                         $( "#divHtml" ).dialog({
                      modal: true,
                    buttons: {
                    Ok: function() {
                    $( this ).dialog( "close" );
                  }
                }
});
                 }
);
});

This will open pop up in document load. If you want to open popup when clicking on button,put above dialog code in button click event handler.

Below are links:

http://api.jquery.com/load/

http://jqueryui.com/dialog/#modal-message

malkam
  • 2,337
  • 1
  • 14
  • 17
  • Does anything particular need to be included to the file to use this? I'm including the source JS file for jQuery 1.10.2 but it says there's no command "dialog" supported at runtime – thnkwthprtls Aug 05 '15 at 20:59
  • 1
    @thnkwthprtls: you need to include jQuery UI javascript files also. Download from here -http://jqueryui.com/download/ – malkam Aug 08 '15 at 18:47